Sign in to follow this  
Jovan

Simple 2D Trajectory

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by Jovan
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.
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 this post


Link to post
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 :)

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