'SharpDX Circle-(Circle or Line) intersection

Hello i'm trying have some fun with SharpDX.

I'm trying to automatic turret fire system and player has to dodge bullets. Bullet's or spells are Line(Laser Beam) or Circle(Grenade Launcher etc.) depends on weapon.

I am using this algorithm for now

It works fine but i figured out i still can hit target if i slightly fire behind of target (for increasing hit chance).

This is the scenario for people like visuals (sorry for powerpoint stuff)

Image1

Target is blue circle which has radius (differs type of unit: soldier, commando etc)

Yellow is the direction of unit. Alien is turret position. Currently code hits center of unit but i want this scenario.

Image2

Looks like i need to calculate unit radius and bullet or spell width which can be differs depends on type: line or circle. It's 2D btw. Ignore 3D stuff like gravity etc. Hope i could explain everything. Thanks.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source