• ### Popular Now

• 12
• 12
• 9
• 10
• 13

#### Archived

This topic is now archived and is closed to further replies.

# moving correctly on a 2d plane

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

## Recommended Posts

So there I am trying to get my poor spaceship to move correctly within the z-plane of my small game. so far: When I hit "left", my ship rotates left by 10 degrees When I hit "right", my ship rotates right by 10 degrees Now when I hit "up", I just want to adjust my ship''s x,y position to move in the upwards direction (as in "vertical up" and NOT as in "towards the viewer") Currently I''m calculating the x and y position thusly:

vecPos.x += sinf(vecRot.z);
vecPos.y += cosf(vecRot.z);

Can anyone see something wrong with this calculation? thanks for any help,

##### Share on other sites
When you press left and right, which axis does the ship rotate around? You want the ship to move along the y axis when you press up, so you have a separate control for throttle? In those calculations you don''t seem to have a velocity, so the ship is moving incredibly slowly at a constant rate.

##### Share on other sites
I''ve got the ship rotating around the z-axis whenever I press left and right..

Yeah it is incredibly slow, but still moving in the wrong direction. Until I figure out the proper direction calculation, I won''t bother working on acceleration..

thanks,

##### Share on other sites
Try reversing the sin and cos functions, or making sure the ship model is pointing in the right direction to start with.

##### Share on other sites
Reversing the sign of the sin and cos functions don''t seem to help.

I''ve gone with:

  m_vecPos.x += sinf(m_vecRot.z) * dwTimeKey * 0.09f;m_vecPos.y += -cosf(m_vecRot.z) * dwTimeKey * 0.09f;

Where dwTimeKey = the difference between the nth and nth-1 frames..

When I push UP now, my ship moves in a NW direction! Very bizarre..

By my calc.exe, if the rotation angle is 180 degrees, sin(180) SHOULD be 0, and therefore the rest of the vector should end up equaling 0. That''s not happening...instead I''m getting a negative vector..

This is one of those things that I should be seeing, but can''t..

##### Share on other sites
hmmmm..
just wondering, doesnt the c math functions for sin,cos and tangent use radians not degree''s. ???

sin(180) is actually in radians.. so its not 0.

##### Share on other sites
quote:
Original post by jwalker
just wondering, doesnt the c math functions for sin,cos and tangent use radians not degree''s. ???

He is right there.

##### Share on other sites
Hyuk...THAT''s what I''m probably overlooking.

Thanks for the advice, I''ll try dropping it into my source code later on.

*Iolo Bows in Appreciation*

It

# worked!

Thanks again crew!! High 5''s all around!