Jump to content
  • Advertisement
Sign in to follow this  

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

This topic is 2671 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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?

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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!