How to make an actor chase another actor?

(Sorry if this question is really simple, I’m very new to this so bear with me)

For my project, I have to make an actor that flees from the player, but also chases another actor. How do I blend these two behaviors together? Because right now, the actor only flees from the player.

Hi @Bubalack2!

There are many different ways to achieve this logic.

One possible solution is to get the distance (D1) from the actor (ActorA) to the player and the distance (D2) from Actor A to the other actor (ActorB).
If D1 > D2, ActorA chases ActorB. If D2 <= D1, ActorA runs from the player. You can use some form of a lerp based on distance to smoothly transition between the two states, rather than a bool.

Another solution for a slightly different effect, get the normalized vector from ActorA to ActorB: normalize(ActorB loc - Actor A loc). Then, get the normalized vector from the player to ActorA: normalize(ActorA loc - player loc). Add the vectors together and divide by two to get the vector in between the player-to-ActorA and ActorA-to-ActorB, then multiply this by a velocity. This way ActorA will always be doing a mixture of both states. In the condition that the player and ActorB are directly across from each other, ActorA would just sit still, and you can fix this by multiplying the normalized vectors by a distance-based weight.