Download

Make AI face player when moving?

It’s pretty integral to my system that the AI face the player at all times when they are “agro”, but I have read that AI MoveTo cannot be overridden by SetActorRotation. What is an alternative method? I am using Behavior Tree.

For example, I want the AI to back away from the player when the AI Pawn’s stamina is too low, and then strafe around them. I can make them do this with AI MoveTo, but they turn their back to the player and then face the direction they’re moving.

In blackboard use rotate to face bb entry. Set blackboard key to be the player the AI is targetting.

That doesn’t really work because it fires just once, so they don’t continuously face the target.
Edit: it also doesn’t seem to make them rotate, either. I’m watching the TargetLocation update as I move around and the rotate node is constantly firing, but it isn’t doing anything.

There are several ways you can achieve this behavior, if you notice aimoveto is an async task and can be used in conjunction with all kinds of behaviors…
One way is to create a custom bttask that disables “orientation to movement” or “controller desired rotation” in character movement, then use the “setfocus” node to focus the player while moving(strafing).

You can also manually interp aicapsule rotation fairly easily - Im no expert but I found using timers bound to ai rotation functions works well. Just pause the looping function timer for different rotation focus states and interp between the states whenever required. Another way although a hack, is to disable/re-enable pawn sensing between different short movements/actions to toggle focus of player.

​​​​Also using the “simple parallel” behavior tree node can achieve this.

Here is a barebones yet very informative tutorial series with some basics, the final part shows one way to achieve what you are wanting:
​​​​​​
https://m.youtube.com/watch?v=2K6nX4A5n8w
​​​​

Thanks for the options karma4jake, I’ll try them out and come back with results.

Followed that tutorial and it all worked out in the end, I learned a lot more than I was expecting to. My original goal of making the AI face me was actually still an issue by the end, he made it look much simpler, but I figured it out. I made a node to set the focus, which is in essence making the AI face a target. I had to change 2 pre-existing booleans every time, here’s how I did it.

The boolean is exposed to the behavior tree so you can choose to set a null focus (remove the focus and set their rotation to default) and the target can be set on the behavior tree as well so you can change it there.

Ya it is definitely more complex than I thought as well, I am still having trouble achieving truly human-like movements with AI. Especially when it has to rotate upper body seperately from lower while moving and still blend everything nicely and return back…Timelines, lerp, rinterp, finterp, interpitselfinterpaloids

I have messed around with lowering acceleration/decceleration values in AI character movement which can help with more realistic behaviors. Of course AI always reacts so quickly to everything it takes so much tuning to get everything right