how to make an actor run away from another actor

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

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

    http://gamesalad.com/game/play/65632
  • aracknoraracknor Member Posts: 54
    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 Member Posts: 54
    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 Member Posts: 1,400
    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 Member Posts: 54
    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
Sign In or Register to comment.