Jump to content
  • Advertisement
Sign in to follow this  
Jovan

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.

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

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

  • Advertisement
×

Important Information

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

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!