# Using Angles on Projectiles

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

## 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 on other sites
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 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.

1. 1
2. 2
3. 3
Rutin
24
4. 4
5. 5
khawk
14

• 11
• 11
• 23
• 10
• 9
• ### Forum Statistics

• Total Topics
633651
• Total Posts
3013127
×