Sign in to follow this  
supervlad

Relative position problem because cos(0) == 1

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this