How to make AI character move away from enemy character

Hello!

I’m kind of puzzled here, making a game about wolves chasing deer.
I coded behavior for chasing for wolf, but i cant make the deer move away from the wolf.
Tried multiple aproaches, though MoveTo, MoveToLocation, also tried inverting GetActorLocation() fvector and using that as the move to, but it doesnt work. I would really appreciate help with thisScreenshot_Code

GetActorLocation is just getting the location where the wolf currently is, I’m not sure that’s what you would want.

Perhaps you want to get the target->GetActorLocation() - source->GetActorLocation() (source is your deer so just get the controlled pawn’s location, then normalize that vector, to get the direction the wolf is heading.

From there you can multiply the direction by a speed, that’ll give you a location somewhere opposite the wolf’s direction, and you could use MoveToLocation or something else.

target - source may give you the direction to the wolf, if that is so, then negate it so -(target->GetActorLocation() - GetControlledPawn()->GetActorLocation())

I didnt quite understand your explanation!
So i do Target->GetActorLocation() - OwnerDeer->GetActorLocation() (OwnerDeer is the ref to controlled pawn), What do i do then? How do i normalize that, and by speed what speed do i use to multiply?


Found somewhat of a solution.

I just want to add that sooner or later you’ll end up with a position that’s unreachable on the nav mesh (inside a wall or a tree, etc…). Don’t worry about this if you are just starting out, but later on you should use an EQS for stuff like this. It’s not as complex as it may seem like at first glance.

Unreal Engine AI with Behavior Trees (YouTube)

Thanks, i have considered that, but i got no time to study new functionality, have to finish this school project with a deadline. After that i was planning to study behavior trees for personal future projects! Thanks for the link.