Skip to main content
GameDev.net gamedev.net
🔒 Locked

DotP for Rotation Direction probem

Started by reaperrar Apr 28, 2012 at 10:22 AM 0 replies 1.1k views
Original Post
reaperrar
reaperrar
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 ><

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.