GameSalad

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

how to make an actor run away from another actor

aracknoraracknor Posts: 54Member
edited November -1 in Working with GS (Mac)
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.

Comments

  • BarkBarkCoBarkBarkCo Posts: 1,400Member
    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...
  • aracknoraracknor Posts: 54Member
    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
  • BarkBarkCoBarkBarkCo Posts: 1,400Member
    Reverse the first two constraints...game to self, not self to game.

    I had that written wrong.
  • jstrahanjstrahan Posts: 498Member
    Simple put a large gun in the hand of the predator that always make me run away lol
  • aracknoraracknor Posts: 54Member
    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.
  • BarkBarkCoBarkBarkCo Posts: 1,400Member
    It ended up being a little more complicated than I thought. ;-) Check out the demo...

    http://gamesalad.com/game/play/65632
  • aracknoraracknor Posts: 54Member
    Wow barkbark00 I think that is it. But how can I do that. but instead of one victim a couple and 1 predator that I will be controling with up, down, left and right.
  • aracknoraracknor Posts: 54Member
    hey barkbark00 i think I got it i will try it tomorrow but in the instructions that you gave me earlier we put the predator close as a boolean attribute but in your Fred it is interger this may have something to do. i will see tomorrow. I will let you know.
    Thanks again I you been amazing.
  • BarkBarkCoBarkBarkCo Posts: 1,400Member
    Yeah, I changed my mind on what I thought was best once I started building it out...I don't remember why exactly. lol.
  • aracknoraracknor Posts: 54Member
    Hey barkbark00
    I followed the fred tutorial and it worked perfect. Thank you for your all your help and and more important thank you for you patient.
    Thanks
This discussion has been closed.