# DotP for Rotation Direction probem

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

## Recommended Posts

I have an AI character who wants to move to a position. He needs to rotate to face the position to walk there.

I'm using the dot product between the AI char's current right direction and a vector from the AI char to the target to determine if it should turn left or right.

 Vec3 oPosRel = this.Pos - Target.Pos; if (oDirection_Right.Dot(oPosRel) < 0.0f) { RotateRight(a_fDeltaTime); } else { RotateLeft(a_fDeltaTime); } 

This works 99% of the time.

Though if suddenly the ai needs to move in the opposite direction it gets stuck rotating in both directions left-right-left-right etc until finally, randomly it stops and rotates properly.

It seems to be relative to the size of "a_fDeltaTime" also. If I have a smooth 60 fps it never happens but if I zoom out dropping to 17 fps it happens every 1/20 direction changes or so.

Am I doing something wrong or should this work?

EDIT: Nvm. Solved >< Edited by reaperrar

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

• 11
• 22
• 12
• 12
• 11
• ### Forum Statistics

• Total Topics
631406
• Total Posts
2999904
×