Question about adding a turning left task in Behavior Tree

Hi all, I am working on an animal animation in UE.
I want to make the animal turn left in 90 degrees slowly while playing a turn left animation.

In Behavior Tree, I add a task and use an AddActorLocalRotation and set the delta rotation to 0,0,-90. The character rotates immediately when executing the task.
I wonder if there is a way I can make it slowly turning left so I can sync it with the turn left animation.

I know there is a FInterp to Constant which can do the linear interpolation by keeping updating the current value with the return value of the FInterpToConstant. but I don’t know how to set an initial current value in a behavior tree task. There is only Event Receive Execute, tick and abort. I failed to find something like BeginPlay in BTTask.

Anybody has idea how to do it? Thank you in advance!

This task needs to be on tick.
no other way as you will need to rotate the character at a given turn rate.

You could also look into TurnInPlace setups. They kinda do what you need.

Thank you for your help!
As I need the character to turn left and then keep walking forward, it seems I cannot use turn in place animation here.

I failed to rotate the character at a given turn rate in the task with the Execute Tick AI. Could you please give me some hints on how to do it?
Thank you very much!

Sure, but perhaps describe more in detail as I would approach things differently based on speed of travel and other parameters.

slow walk or run?
Also, move towards what? Are we having the AI follow something or is it just going to its own point?

as far as something you can try to get the rotation to rotate (probably as you have).

Break the rotator pin out so you can isolate the Z.
Get a lerp node in, and set the lerp between the current actor rotation/break pin z, and the value you want.

stop the task with success if the current turn rate is nearly equal to what you want (give it a margin of error of about 2 since it doesn’t necessarily have to be spot on). Otherwise continue the task execution.

At a base level that will do what you needed as you already explained

Thank you so much for your advice! :smiley:

For my case, I have an animal character which has a turn left in 90 degrees animation with root motion enabled.
In Behavior Tree, I am trying to make the animal turn left in 90 degrees slowly at the starting position and at the same time the turning left animation will be played, so that the animal will look like he is turning left naturally without foot slide. And then a new task of moving to a new location will be fired so the animal will walk forward.

I created a task in which I use an AddLocalRotation and set the Z to 90 to make the character turn left. Without the lerp, the animal will turn left in 90 degree immediately instead of slowly.
Below is my idea of how to do it with the Lerp.
I know this is definitely wrong. The variable Current should be given an initial value as zero when the task begins. And also the task should stay at the InProgress status before the Z reaches 90. Now it is always finished with a failure status and restart itself again and again.

I wonder how to give the variable Current an initial value when the task begins and how to tell the task to stay at the InProgress status so that it can wait till the Z reaches 90.

Or is there another way to do it?

Thank you so much!

If you have turn in place set up as you say, all you have to do is change the animation blueprint value for the rotation and the animations will play as they are supposed to do. You dont need to lerp or anhthing since the animation takes care of it all.
check on that.

To activate it, the best way is a custom event on the character that you can change to a blueprint interface to avoid casting in behaviour tree.

Do you mean using a blendspace? Sorry I am not clear about what you mean by change the animation blueprint value. :frowning:

I am not sure if I understand it correctly. The Root Motion animation is gonna do the rotate the animation but the mesh won’t be rotated. And the In Place animation will rotate the mesh. In both cases, the capsule won’t be rotated. The MoveTo in Behavior tree is moving the capsule. So the orientation of the capsule determines the direction it is going to move to.

If these are correct, my initial idea is to play the rotate animation with root motion enabled and at the same time I rotate the capsule in behavior tree. So if my rotate speed matches the rotate animation, the character will look like it rotates naturally. Is it a correct method?

I think you need to look into how turn in place works a little more.

Usually you have 1 animation for the turn that does not turn. The animation blueprint takes care of rotating the root bone based on a curve value that is part of the animation itself.
Yes you could use root motion. But usual setups work on characters that can actually network, so they don’t really show you the root motion way.

Either way, the animation feeds a value to the rotate root bone node, over time.
but the triggertring of the animation is always based on what has already occurred.

In a standard setup you have the rotation of the previous frame, and the current rotation. Thus you can calculate the degree of turn that has occured in the last frame and fire off the appropriate animation.

Ergo, if you suddenly twist the character capsuse by 90° in a direction, the animation plays and automatically adjusts the rotation of the mesh over time as defined by the animation.

Which in turn (im funny afun’t I) also works fine with any AI or code that bumps the rotation of the mesh from where it used to be to any value at all.

Look into the Paragon turn in place tutorials to implement it right.