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

## 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 on other sites
Make the speed 0 when there's no rotation set.

##### Share on other sites
That's not a good solution because if the speed ever changes, the model still moves to the wrong direction.

##### Share on other sites
Then set the rotation to the direction it should be going.

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

What am I getting wrong?

##### Share on other sites
Try this: change sin <-> cos, and play around with the signs

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

1. 1
Rutin
25
2. 2
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 14
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631759
• Total Posts
3002138
×