Support Forum

Rotate to face object at end of path

I am trying to get my AI to face a specific transfrom after reaching its destination but cant get it to work.

RotateTowards(lookDirection.position);

I am using this ^^ code in order to do it and am using it in the OnTargetReached () function.

When it gets there it fights with something else so it will look for a millisecond the try to look at something else. I am wondering where the other look at the end of path is so I can comment it out or fix it.

Any help is appreciated. Cheers.

Well… Im not sure what the issue is~

But here is some simple code:
`
C#

OnTargetReached(){
Quaternion LookAt = Quaternion.LookRotation(LookAtThisThing.position);
this.transform.Rotation = LookAt;
}

`

You can also Slerp it for smoother effect:
`
C#

OnTargetReached(){
Quaternion LookAt = Quaternion.LookRotation(LookAtThisThing.position);
LookAt = Quaternion.Slerp(this.rotation, LookAt , Time.deltaTime * Speed);
this.transform.Rotation = LookAt;
}
`

Or if you want to look in a direction, not at a point, you can use eulerAngles
C# OnTargetReached(){ Player.rotation = Quaternion.Euler(0, YRotation ,0); }

Hope That helps!

1 Like

Maybe I should have clarified better. I am building off the botAI that comes with the package in example 2. I have done what you said but when it starts to rotate it keeps snapping back to looking at something else. I don’t know where or what is telling it to look away.