Simple 2D Trajectory
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?
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...
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.
Anyway, what you suggested was the first thing I tried. Didn't work out quite well.
Quote:Original post by JovanHm, 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?
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.
If not, perhaps you could post some code.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement