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

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627700
• Total Posts
2978695

• 21
• 14
• 12
• 10
• 12