Jump to content
  • Advertisement
Sign in to follow this  
supervlad

Relative position problem because cos(0) == 1

This topic is 3258 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

In the engine I'm using, the standard for the forward direction is on the +x axis. This presents a problem for me when doing the motion of a model. Currently, I'm moving my model using:
model.position += directionVector * speed * deltaTimeInMillis
model.position is a vector/point I'm computing the direction vector as such:
directionVector = Vector(-sin(angleRadians), cos(angleRadians, 0)
This presents a problem because cos(0) == 1, so at the beginning, when there is no 'rotation' set for the model, it still moves towards the left because of cosing(0) being 1. Without making my model facing the Y axis, how can I deal with this? Thanks

Share this post


Link to post
Share on other sites
Advertisement
Why would you set a speed when there's no direction to move to?

Looks like you need secondary logic to control this, like an isMoving flag.

Edit: Wise words SiCrane.

Share this post


Link to post
Share on other sites
The forward direction is on the x axis, but that's not sufficient to define a 2D orientation. Assuming the typical 2D basis, X points right and Y points up.

So:
forward is (1, 0) ~ 0 rad [2Pi]
left is (0, 1) ~ +Pi/2 rad [2Pi]
backward is (-1, 0) ~ Pi Rad [2Pi]
right is (0, -1) ~ 3Pi/2 rad [2Pi]

Your default orientation is 0 rad, and you want it to point forward.

Therefore directionVector = Vector(cos(angleRadians), sin(angleRadians, 0)

What am I getting wrong?

Share this post


Link to post
Share on other sites
Try this: change sin <-> cos, and play around with the signs
I mean: directionVector = Vector(cos(angleRadians), sin(angleRadians), 0)

Edit: Sorry, I didn't read the above post...

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!