Modify AI Move To to rotate and move forward

Hello,
I want recreate project on UE4 from Unity. In example project character move to point and rotate to move direction. I want it rotate and move only forward direction and not have problem with physics and not stuck on obstacles. Surf goolge and forum did not bring the results.

100665-aipath.jpg

Just to clarify you don’t want the character to walk backwards for example? You want to avoid these kind of thigs and have the character to always walk forward, right?

Yes I want that the character not move backwards. If player click behind his back, character start rotate and move in face of rotation.

Hey,

You have to write your own class UCustomPathFollowingComponent with as parent UPathFollowingComponent
and overwrite the function FollowPathSegment(float DeltaTime) to the desired effect.
Take a look at this documentation for some details: https://wiki.unrealengine.com/AI_Navigation_in_C%2B%2B,_Customize_Path_Following_Every_Tick

Hope this helps :slight_smile:
Elias

I saw that topic and based on my experience, I am afraid that the character will be hit into obstacles because character path always calculated for current point to end point. But character movement vector not equal to current path segment vector. Thanks for the quick response, I will try this in any way.

Yes this happens, but only in certain situations,

you could make the AI raycast in front of him and slow his speed down if it hits something, this way he will even react like real humans :slight_smile:

Take a loot at the SetFocus/SetFocalPoint function of AI_Controller. This functions specifies at which object does the character looks (or location) when moving. It has different priorities. I think it is what are you looking for and it is far easy.

The path that the character follows is the same, the only thing that it changes is the rotation of the characther (the direction that is facing). It has multiple priorities, the character can move to a point always facing that point, even if they are obstacles; or it can focus middle points moving towards the final destination (as humans do).

Is seting focal point controlling movement direction?

I did it by having my AIController class override UpdateControlRotation to turn slowly towards the next focal point (GetFocalPoint). I then set the character walk/run speed to zero in the character movement settings, and updated the character location manually by something like NewPos = OldPos + (MyMoveSp * DeltaTime * GetActorForwardVector());

As you can imagine, the character didn’t stay exactly on the nav path, but it wasn’t a big deal in my case. There is no navigation function in Unreal that does exactly what you want (a nav path with tangents that take into account rotation speeds). If you want one, you’d have to write it and hopefully share it with the rest of us :slight_smile:

In a case such as you showed, Epic would prefer you add a turn around animation that gets the player pointed in the right direction, and then navigate as normal.

Hello. I read your post.
So you want to say…
When AI rotate to move forward, we should use animation?.. Is it right?

If AI is huge size, Epic’s Rotation Rate modification method looks very strange…
because AI move to opposite direction and footstep is not synced.

Simple solution that worked perfectly. From Blueprint Editor

In your Class (first item in your component list, above CapsuleComponent) uncheck “Use Controller Rotation Yaw”

In your CharacterMovement component, check “Orient Rotation to Movement”

Source

2 Likes

That works perfectly thanks for pointing out.

Thank you!