Question by
Gameatro · Mar 31, 2020 at 11:20 PM ·
animationanimator controlleranimationshumanoid
Walking animation of character appear broken when combined with NavMesh Agent
I am trying to make a small game where a zombie follows the player and attacks on getting near. But it is appearing broken. Here is the video: link text Here is my code controlling the Zombie:
void Update()
{
agent.SetDestination(player.position);
if (agent.pathPending)
return;
float speed = 0.0f;
if (agent.remainingDistance <= agent.stoppingDistance*stopDistanceProportion )
{
agent.isStopped = true;
animator.SetBool("PlayerClose", true);
transform.LookAt(player);
}
else if(agent.remainingDistance < 50.0f)
{
float proportionalDistance = 1f - agent.remainingDistance / agent.stoppingDistance;
transform.LookAt(player);
speed = Mathf.Lerp(0.5f, 1f, proportionalDistance);
agent.isStopped = false;
animator.SetBool("PlayerClose", false);
}
else if (agent.remainingDistance < 150.0f)
{
Quaternion targetRotation = Quaternion.LookRotation(agent.desiredVelocity);
float proportionalDistance = 1f - agent.remainingDistance / agent.stoppingDistance;
transform.LookAt(player);
speed = Mathf.Lerp(0f, 0.5f, proportionalDistance);
agent.isStopped = false;
animator.SetBool("PlayerClose", false);
}
else
{
agent.isStopped = true;
animator.SetBool("PlayerClose", false);
speed = 0f;
}
animator.SetFloat("Speed", speed);
}
The zombie starts attacking animation when "PlayerClose" is set true and the Speed is used to control walking, running and Idle. Idle on 0, walk on 0-0.5 and run on 0.5 to 1. But when the Zombie gets close and start attacking and I move the player, the movement of the Zombie is not smooth, it slides across the floor and looks broken. So why is this happening? I am new to Unity animations, so please guide me.
Comment