# Simple 2D Trajectory

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

## Recommended Posts

I've searched around the site but couldn't find anything really relevant. The problem isn't very hard but I can't get it to work given that I've already made it before less than a year ago! I am trying to get a "bullet" in this case to travel across the screen towards the cursor. I already have the necessery calculations such as angle between soldier and cursor (relative to the soldier, of course) and the x/y distance between soldier and the cursor. Although it isn't really relevant I am rendering using OpenGL. I have good knowledge of trigonometry, I just can't seem to clue in on how to do this (despite me sketching it out even). The angle is of course simple, yet I have no idea how to set the x and the y velocities with respect to the angle. Any ideas?

##### Share on other sites
Are you just looking for velocity_x = cos(angle), velocity_y = sin(angle)? That's the most obvious thing that comes to mind, although 'angle relative to the soldier' could mean different things...

##### Share on other sites
What I meant by angle relative to soldier is that the angle which soldier is facing is directly calculated from his position to the cursor, rather from the center (I had that problem before, I set up the screen as a 2D cartasian plane with 0, 0 in the middle and did angle measurements with that, bad idea).

Anyway, what you suggested was the first thing I tried. Didn't work out quite well.

##### Share on other sites
Quote:
 Original post by JovanWhat I meant by angle relative to soldier is that the angle which soldier is facing is directly calculated from his position to the cursor, rather from the center (I had that problem before, I set up the screen as a 2D cartasian plane with 0, 0 in the middle and did angle measurements with that, bad idea).Anyway, what you suggested was the first thing I tried. Didn't work out quite well.
Hm, without further info, I'm really not sure. How did it not work? Is it perhaps the old 'C++ trig functions work with radians, not degrees' gotcha?

If not, perhaps you could post some code.

##### Share on other sites
Actually jyk I found my old code and found out how do it without needing the angle (X and Y distance was enough, then just use cosine and sin with an incrimenting number). Should work.

Thanks anyway though :)

1. 1
Rutin
21
2. 2
3. 3
JoeJ
18
4. 4
5. 5

• 13
• 38
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631715
• Total Posts
3001868
×

## Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!