how to make an actor run away from another actor

Member Posts: 54
edited November -1
Hi everyone this is my first question of many, many to come. how can i make an actor (the victim) move normal but as soon as an actor (the predator) gets close, the victim tries to get away until it reach certain distance. This must be like the opposite of how to create a follower but i just can't figure it out.

• Member Posts: 1,400
If there are multiple predators, I would do the following:

Create 6 Game attributes
-VictimX (Integer)
-VictimY (Integer)
-Proximity (Integer) // set to desired effective radius.
-PredatorClose (Boolean)
-PredatorX (Integer)
-PredatorY (Integer)

In the Victim actor...
Constrain self.position.x to game.VictimX
Constrain self.position.y to game.VictimY

In the Predator actors..

Rule
When ALL conditions are valid:
When an attribute changes:
Game.Proximity >= magnitude(self.position.x-game.VictimX,self.position.y-game.VictimY)
AND game.PredatorClose = false
-----Change PredatorX to self.position.x
-----Change PredatorY to self.position.y
-----Change game.PredatorClose to true
otherwise
-----Nothing here

Back in the Victim actor...

Rule
When ALL conditions are valid:
game.PredatorClose = true
AND Game.Proximity >= magnitude(self.position.x-game.PredatorX,self.position.y-game.PredatorY)
-----Accelerate Toward: position x = game.PredatorX, position y = game.PredatorY (relative to scene), speed -100(minus is key!)
otherwise
----- add desired stopping/slowing logic here...
----- Change game.PredatorClose to false

I will test this and update if needed when I get home tonight...
• Member Posts: 54
Hi Barkbark00. I tried that but every time i hit the preview the victim disappear and appear in the lower left corner. I move the predator and the victim stays in the same place (lower left corner). In the otherwise of the rules for the victim you told me to ad the desired stopping /slowing logic, can you elaborate in this too.
Thanks
• Member Posts: 1,400
Reverse the first two constraints...game to self, not self to game.

• Member Posts: 498
Simple put a large gun in the hand of the predator that always make me run away lol
• Member Posts: 54
Hi barkbark00 I change those 2 in the victim and now when i hit preview the victim does not move at all And jstrahan, I tried the gun suggestion but the victim is too stupid or is facing the other way.
• Member Posts: 1,400
It ended up being a little more complicated than I thought. ;-) Check out the demo...