how does an enemy move to the players direction - not following him?

mhmmamhmma Member Posts: 5
edited September 2012 in Working with GS (Mac)
I have a bat enemy which attacks the player when the player is near it. Is it possible that the bat moves in a direction to the player but not to the players X and Y position - not the MOVE TO POINT behavior because than it follows the player all the time the bat only should fly in the direction to the player so the player is able to avoid the enemy.

(sorry for my bad english hope everything makes sense)

Answers

  • decaoeudecaoeu PRO Posts: 61
    Create 3 atributes in the game, lets say Player X, and Player Y, TRIGGER.
    Then create a rule that say, when the ENEMY SPAWN set TRIGGER to TRUE.

    Then Create a rule in the player that says when TRIGGER is true, change attribute, Player X to Self.Postion X. Do the same thing for the Y position.

    That should work
  • mhmmamhmma Member Posts: 5
    edited September 2012
    thanks for your answer ... but it doesnt works the way i want to ... because when the bat reaches the x and y coordinates of the player it just stops there ... but i found a solution:

    to get an angle for the direction towards the player you have to do this
    make a rule if game.player.x is < self.position.x
    then use the move behavior and in direction insert:
    atan((game.player.y-self.position.y)/(game.player.x-self.position.x))+180

    and if game.player.x is > self.position.x
    atan((game.player.y-self.position.y)/(game.player.x-self.position.x))

    then just use some triggers so that the enemy just gets the angle once and the bat flies in the correct angle (direction) towards the player and dont stops at the players coordinates
Sign In or Register to comment.