Jump to content
  • Advertisement
Sign in to follow this  
Loredivine

Using Angles on Projectiles

This topic is 2859 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

I've started work on a 2-D shooter, and decided that you were two be one stationary object firing from different angles. I haven't really been taught how to apply Trig to anything, just the mathematics of it.

The situation I'm going for is: You are one, static positioned object in the space, and you have to shoot enemies trying to attack you. Your object in space has an angle variable, which the bullet receives, and fires in that direction. How would I send the bullet on said angle (i.e. 10 degrees) only moving by so many pixels (i.e. 5 px) per frame? (sort of an Asteroids approach, but you can't move)

Share this post


Link to post
Share on other sites
Advertisement
velocityX = cos(angle) * speed
velocityY = sin(angle) * speed

In your example angle = 10 deg (usually sin and cos want radians so you have to convert to that)
Speed = 5 px/s

Usually it's easier to store the computed velocity vector rather than its speed (magnitude) and angle (direction).

Keep in mind the computed velocity above is relative to the source object's velocity, if the source is moving you have to add the source object's velocity. I.e. world_velocity(new_object) = local_velocity(new_object) + world_velocity(source)

Share this post


Link to post
Share on other sites
Alright, thanks for the help man, that seemed to do the trick. Now I can show my math teacher how to apply the stuff she's taught us in class. Cheers.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!