I just started using this asset today and I made a simple AI using the Behavior designer asset to make the AI wander around… the problem is the AI walks in circle never reaching the destination…
I also have a custom script attached to the AI that uses:
void OnAnimatorMove()
{
//only perform if walking
if (moveState != MoveState.Idle)
{
//set the navAgent's velocity to the velocity of the animation clip currently playing
aIPath.Move(animController.deltaPosition);
}
}
I don’t think this is the cause because I removed it and I still had the same problem.
Do you perhaps have root motion enabled on your animation controller? That would cause the agent to move forward more than it expected and fail to turn around in time.
ok so i found what is causing this… but im not sure how to fix it
using UnityEngine;
using BehaviorDesigner.Runtime;
using Pathfinding;
public enum MoveState { Idle, Walking, Run}
public class AIAnimations : MonoBehaviour
{
[ReadOnly, SerializeField] private MoveState moveState;
[Space(10)]
[SerializeField] private Animator animController;
[SerializeField] private AIPath aIPath;
[SerializeField] private BehaviorTree agent;
[Space(10)]
[SerializeField] private float walkSpeed = 1.5f;
[SerializeField] private float runSpeed = 3f;
void Update()
{
var danger = (SharedBool)agent.GetVariable("Flee");
//character walks if there is a navigation path set, idle all other times
if (aIPath.hasPath && !danger.Value)
moveState = MoveState.Walking;
else if (aIPath.hasPath && danger.Value)
moveState = MoveState.Run;
else
moveState = MoveState.Idle;
if (moveState == MoveState.Run)
{
animController.SetFloat("Speed", runSpeed);
}
else
{
animController.SetFloat("Speed", walkSpeed);
}
//send move state info to animator controller
animController.SetInteger("MoveState", (int)moveState); // <-- this is what is causing the problem..
}
void OnAnimatorMove()
{
//only perform if walking
if (moveState != MoveState.Idle)
{
//set the navAgent's velocity to the velocity of the animation clip currently playing
aIPath.Move(animController.deltaPosition);
}
}
}
whenever the script changes the animation it causes it
The line you pointed out only changes what animations play. But it doesn’t directly influence the movement.
This one
aIPath.Move(animController.deltaPosition);
does influence movement, however. Which is why I think it’s the problem. If not this line, then you have some other code that uses animation data to drive the agent’s position and/or rotation.
ok so I disabled RootMotion and it fixed the problem… Thanks!
and another question… is the MaxSpeed works as like a current speed for an example if an enemy is chasing the AI and I increased the max speed is it going to be faster? because now I need to change speed from your system