- Home /
Question by
KaidaStudios · Sep 06, 2016 at 04:40 AM ·
aimecanimwander
Wander AI Mecanim Help
I am trying to just make the animation stop in Idle before walking again, but it just starts looking around and keeps walking in place until it starts moving again. Trying to make this Wander script look realistic. I cant seem to understand why its not working correctly.
void Update()
{
timer += Time.deltaTime;
if (agent.velocity != Vector3.zero)
{
anim.SetBool("Wander", true);
}
else
{
anim.SetBool("Wander", false);
}
if (timer >= wanderTimer)
{
Vector3 newPos = RandomNavSphere(transform.position, wanderRadius, -1);
agent.SetDestination(newPos);
timer = 0;
}
else
{
}
}
public static Vector3 RandomNavSphere(Vector3 origin, float dist, int layermask)
{
Vector3 randDirection = Random.insideUnitSphere * dist;
randDirection += origin;
NavMeshHit navHit;
NavMesh.SamplePosition(randDirection, out navHit, dist, layermask);
return navHit.position;
}
}
Comment
Your answer
Follow this Question
Related Questions
Need to walk idly around unless ball is around 1 Answer
how to set mecanim parameters for an ai? 0 Answers
Random Wander Ai 0 Answers
AI Mecanim Movement help!! 1 Answer