2D movement around the screen, different speed depending on direction
I'm hoping this is the best forum for this problem i'm having.
I'm just starting out in directx and i'm working on a 2D asteroids clone.
I've made myself a triangle which can rotate about its centre and move forwards along the screen.
The problem i'm having is that when its moving UP/LEFT and DOWN/RIGHT on the screen, it moves faster than when its heading UP/RIGHT and DOWN/LEFT.
This shouldnt happen the speed should be constant.
This is what i'm using to calculate the speed:
y_speed = (cos(fRotation_angle)*thrust);
x_speed = (-sin(fRotation_angle)*thrust);
fCentreY += x_speed; //the Y co-ord of the centre of the ship
fCentreX += y_speed; //the X co-ord of the centre of the ship
Any ideas whats going wrong?
Nope... that should work just fine indeed.
As a side note you are adding x_speed to fCentreY and y_speed to fCentreX.
As a side note you are adding x_speed to fCentreY and y_speed to fCentreX.
Quote:Original post by b34r
As a side note you are adding x_speed to fCentreY and y_speed to fCentreX.
...which is actually correct because the sin/cos for the speeds are backward. Remember, cos(theta) = x/r, and sin(theta) = y/r.
hmmmm..
well i worked it out this way
straight up in the Y direction is set as the default position - 0 degress rotation.
90 degrees rotation then is straight right accross the screen in the x direction
sin 90 = 1
180 degrees rotated is straight down the screen,
cos 180 = -1
So it all seemed to work out nicely that way..
Whats wrong with that? Its been way way too long since ive done any kind of maths (except a bit of probability..)
well i worked it out this way
straight up in the Y direction is set as the default position - 0 degress rotation.
90 degrees rotation then is straight right accross the screen in the x direction
sin 90 = 1
180 degrees rotated is straight down the screen,
cos 180 = -1
So it all seemed to work out nicely that way..
Whats wrong with that? Its been way way too long since ive done any kind of maths (except a bit of probability..)
Since your code is ok, the problem must be elsewhere!
Just a thought:
Have you limited your framerate?
Maybe your framerate goes done you do not move along one of the axis (beacuse the cos and sin takes longer to compute). Try to get some output of your framerate or limit it to 30FPS.
Good luck,
Nathan
Just a thought:
Have you limited your framerate?
Maybe your framerate goes done you do not move along one of the axis (beacuse the cos and sin takes longer to compute). Try to get some output of your framerate or limit it to 30FPS.
Good luck,
Nathan
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement