Animation help :)

Moodacow

New member
Hello,

I just got the asset and I'm trying to make a rabbit wander around using the wander action.. but I'm trying to make the rabbit play the walking animation when its not paused and I want the animation to play idle animations when the wander action is in the paused state.

I only managed to make it walk but the animation still plays even after pausing.

so what should I do? and what am I doing wrong?

Thank you!
 
I looked at this and I didn't really understand what it meant by "The recommended approach to syncing animations within your behavior tree is to not sync the animations at all within the behavior tree." I tried the thing above though and it didn't work for me because the action it self will run forever so there is no way to end it and make the parameter change the value.

but I just want to understand what it meant because I tried to look into it with the links provided (the tutorials) but it didn't really show what to do or how to implement it without coding it myself..?
 
The best approach is to do some coding for the animation system. You could use the Animator Controller tasks within the behavior tree but this is not very flexible once you start to add a decent number of tasks. I would love to be able to include something like this with Behavior Designer but every Animator Controller is different so there's not a generic way to make it work for every project.

Our character controller (which is integrated with Behavior Designer) is setup similar to the code tutorial where you don't need to explicitly set the animator state within the behavior tree.

I tried the thing above though and it didn't work for me because the action it self will run forever so there is no way to end it and make the parameter change the value.
What task? All of the animator tasks return success the same tick.
 
ok so what I was trying to do is to have it like this: Set float parameter(1) to play the move animation > wander > set float parameter (0) to make it idle

but its not working for me since the wander action wont end right? so what do i exactly need to do in this case?
like do I try to make my own script or am I able to do it differently im unsure
 
It depends on what other actions you want your tree to have. I generally recommend using conditional aborts to stop the wander task. After the conditional abort you can set the float parameter to 0. This is from the character controller integration but it provides a great introduction for how to structure your behavior tree:

 
I've thought about that but if lets say I want the AI to just wander randomly and in the wander action it pauses randomly after a few seconds and then it continues I want to make it when it pauses to also switch animations but the wander action doesn't support that. so that's what i'm having trouble with..

so conditional aborts doesn't sound right for me in this case.
 
so far I just want the AI to just move randomly around the world and thats it. I managed to do it with the wander but the animation is just the only thing im struggling with.
 
Conditional aborts are perfect in that case. You could create a new conditional task that randomly returns success after a random interval. The conditional abort would then interrupt the wander task.

You could also do something a little more advanced and use the parallel task and have wander always running. In another branch you can then check the speed of the character and change the animator parameter based off of that.
 
Ok so I think I managed to do it but I'm not sure if that's the way to do it ill show you maybe you can point things out to help me improve it.

You could also do something a little more advanced and use the parallel task and have wander always running. In another branch you can then check the speed of the character and change the animator parameter based off of that.

I tried to do what you said and this is how I did it.. not sure if it's good or not but it worked I guess?

Screenshot 2022-07-16 220956.png

The second thing that I did which is the Check Velocity action as you can see in the image.

I made a script to Check if the Agent's velocity value is greater or less than the storeValue and if so it will return failure, but will succeed if nothing happens.


This is the script:
C#:
using UnityEngine;
using UnityEngine.AI;

namespace BehaviorDesigner.Runtime.Tasks.Unity.UnityNavMeshAgent
{
    [TaskCategory("Unity/NavMeshAgent")]
    public class CheckVelocity : Action
    {
        [Tooltip("The GameObject that the task operates on. If null the task GameObject is used.")]
        public SharedGameObject targetGameObject;
        [SharedRequired]
        [Tooltip("The NavMeshAgent targeted velocity")]
        public SharedFloat storeValue;
        [Tooltip("Use this if you want to make the navmesh velocity in the if statement greater than instead of less (The result will always return failure if the requirment met)")]
        public SharedBool greater;

        [Tooltip("This will Debug Log the velocity")]
        public SharedBool debug;

        // cache the navmeshagent component
        private NavMeshAgent navMeshAgent;
        private GameObject prevGameObject;

        public override void OnStart()
        {
            var currentGameObject = GetDefaultGameObject(targetGameObject.Value);
            if (currentGameObject != prevGameObject)
            {
                navMeshAgent = currentGameObject.GetComponent<NavMeshAgent>();
                prevGameObject = currentGameObject;
            }
        }

        public override TaskStatus OnUpdate()
        {
            if (navMeshAgent == null)
            {
                Debug.LogWarning("NavMeshAgent is null");
                return TaskStatus.Failure;
            }

            if (debug.Value)
                Debug.Log(Mathf.Abs(navMeshAgent.velocity.z));

            if (Mathf.Abs(navMeshAgent.velocity.z) < storeValue.Value && !greater.Value)
                return TaskStatus.Failure;

            if (Mathf.Abs(navMeshAgent.velocity.z) > storeValue.Value && greater.Value)
                return TaskStatus.Failure;

            return TaskStatus.Success;
        }

        public override void OnReset()
        {
            targetGameObject = null;
            storeValue = 0;
            greater = false;
        }
    }
}

Everything is working fine but I just want to know if there are things to improve.

Thank you :)!
 
Last edited:
That looks good. Setting the animation parameters within the behavior tree is definitely managing the agent at another level but with a small tree what you have is possible.
 
The larger that your tree is, the more chance there is that you will need to change the animator parameter. This makes your tree a lot more verbose than if the character controller was managing the animation parameters. With a small tree it's easy to manage though.
 
ok so what I should do is to make my own script to make the character controller manage the animation parameters?

because I was actually asking this before but I wasn't sure how to approach this.

And I'm assuming that the UCC as an example has its own script that isn't related to the Behavior designer to manage the animations? is that right? If that's how you approached it I guess I should approach it this way as well.
 
ok so what I should do is to make my own script to make the character controller manage the animation parameters?
Yes, that's correct. The Synchronize Animations page has a link to an example but it depends on your animator/character setup so there's not one right way to do it.

And I'm assuming that the UCC as an example has its own script that isn't related to the Behavior designer to manage the animations? is that right? If that's how you approached it I guess I should approach it this way as well.
Yes, that's correct.
 
Top