Sign in to follow this  

DotP for Rotation Direction probem

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

If you intended to correct an error in the post then please contact us.

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.

[CODE]
Vec3 oPosRel = this.Pos - Target.Pos;

if (oDirection_Right.Dot(oPosRel) < 0.0f)
{
RotateRight(a_fDeltaTime);
}
else
{
RotateLeft(a_fDeltaTime);
}
[/CODE]

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

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

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