Sign in to follow this  
navid

auto-aim gun like the one used in Jets n Guns

Recommended Posts

hi all
i'm writing code for a small 2d shooter game similar to Jets n Guns, i'm trying to implement a auto-aim gun for my spaceship but i just can't get it working.
my gun have a position, initial rotation & a direction vector for shooting bullets along it & i have a target which obviously has a position. i want my gun to rotate
automatically around its center until it faces the moving target & then fire.
can anybody help me please?
thanks.[img]http://public.gamedev.net/public/style_emoticons/default/sad.gif[/img]

Share this post


Link to post
Share on other sites
Constant speed using longitude and lattitude:
By representing both the target direction and current direction in polar coordinates, you can take the linear distance in polar space. If the distance is lesser than timestep * speed, place it at the goal, otherwise move it closer. This method can be alloying if the gun have to move a large angle but will not have a crazy acceleration in the start.

Exponentially decreasing:
Without polar coordinates, lerp between the current direction and the target direction and normalize. This method require fixed timesteps because of the normalization but makes it look like the engines are limited by acceleration instead of friction.

Applied forces:
Treat the direction as normalized positions and try to accelerate the gun direction to the target direction. To not comming in too fast, calculate where the gun would be directed after some time. If it is shaking at the goal, just lock to the target direction if distance to target + speed is within a treshold.

If the enemy is moving, use linear interpolation of where the enemy will be after the time it takes for the projectile to reach the enemy at it's current location. For more accuracy, iterate the process 3 times by using the result location as the current location.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this