I’ve been experimenting with AI Controllers and my Unreal Guys walking towards random locations in the game world. As such I needed a way for them to turn smoothly towards said random locations before they starting to walk. Thankfully I found out about the Find Look At Rotation node. It was exactly the missing piece to this brainteaser.
Here’s how I made my Unreal Guys turn towards a new location:
This is a custom event on my character. It’s called from my custom Behaviour Tree Node, passing in a new Vector called New Location. First I’ll grab my capsule component’s World Location and use the Find Look At Rotation node to get where (or what) my character should be looking (at). This node needs the new location to give us a Rotation value. I’ll break that struct and access the Z rotation.
I’ll also grab my current World Rotation and find out where my character is currently looking at. Again the Z rotation is all I need to proceed. We need to find a way to interpolate between these two values, then continuously update the Z rotation until we reach the new value. At that point, we’re looking towards where we’re going to walk next.
To interpolate these values, I’m using a combination of Timeline and Lerp Node. The Timeline will give us a float value between 0 and 1 interpolated over one second. When plugged into the Lerp Node, it’ll interpolate between two values of the same kind and give out the interpolated value (in our case, the Z rotation). We’ll use that to make ourselves a new Rotator, which will then update our current World Rotation.
Lerp nodes are very flexible. It stands to reason that the breaking/making rotations could be avoided, since the Lerp can deal with blending two rotators. I’ve tried this too, but it leads to weird results on the characters. I’d advise against it. It would make for a neater Blueprint though – check it out:
On a personal note, I was quite surprised that with my limited knowledge of Unreal Engine, I managed to work out this rather complex equation. I’m beginning to understand how Unreal Engine thinks 🥰
Hello!!
Any chance you could show a screenshot of the timeline window?
🙂
I don’t think I have this project accessible anymore, but there was nothing on my timeline if I recall. It’s all done in Blueprint.
Thanks for looking. I got it all to work apart from the timeline. The character just snaps to the rotation and won’t animate. I guess I’ll keep trying!
Oh you mean the timeline node right, not the actual keyframe timeline in Unreal Engine? Sorry, had a blond moment there! The node is what makes the interpolation happen, so that would have been a 1 second duration, with 0 at the front and 1 at the end.
There’s a screenshot of the timeline node in this article, under the section Animating the Door: https://www.versluis.com/2020/07/unreal-sliding-door/
Wow thanks so much! I will give that a go tomorrow 🙂 🙂
Hi, Thanks for sharing! I’m trying to adapt your tutorial in my scene, where I have an actor following a spline, and when it reach the end it rotate, so it’s working.
But when I try to rotate the actors with splines, it reduce the rotation till it stop after keeping changing the rotation in the scene, how can I set the right amount of rotation I need?
Solved