- Home /
Question by
trevorchico · Jan 31, 2017 at 08:35 PM ·
navmeshnavmeshagentlookatglitchingtransform.lookat
NavMesh Lookat causes jittery glitch in character
Quick Video: https://www.youtube.com/watch?v=xelPUNeJafM
Hi I'm updating my enemy destination and Lookat rotation every .25 seconds to follow the player. but the LookAT function is causing the enemy to glitch and move up for a frame... any ideas on a fix or workaround?
When I remove the lookat code it doesn't glitch.
Code:
IEnumerator checkdist()
{
dist = Vector3.Distance(player.transform.position, this.transform.position);
while (dist>10.5f)
{
nav.transform.LookAt(player.transform.position);
nav.SetDestination(player.transform.position);
dist = Vector3.Distance(player.transform.position, this.transform.position);
yield return new WaitForSeconds(.25f);
}
print("attack");
StartCoroutine(hurtplayer());
nav.speed = 0;
yield return null;
}
Comment
NV$$anonymous$$ figured it out:
nav.transform.LookAt(new Vector3(player.transform.position.x, this.transform.position.y, player.transform.position.z));
LookAT Y was causing it to rotate upwards.
Your answer
![](https://koobas.hobune.stream/wayback/20220612110029im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Navmeshagents stopping for no reason. 3 Answers
Best way to place a name tag over a player? 1 Answer
How do I get agents to avoid each other? 0 Answers
NavMesh Jumping Unity Indie 0 Answers
NavMesh giving jerky like motion 0 Answers