Enemy Chase

Hi Guys, I have a basic enemy chase going on with my hero when he gets close to the enemy. It works well, but I get some odd behavior when the hero is below or above. Here is a drop box link to the test file. Can someone take a look and see if they can find a way for the chase NOT to happen if the hero is below or above.

arrow key move the character around. You will see what I mean when the hero is on the ladder above or below the enemy

Thanks in advance.

https://www.dropbox.com/sh/t8joozvighev9ci/AAAiamX3vsq-z9PZOozXBF_za?dl=0

Comments

  • NNterprisesNNterprises Member, PRO Posts: 387

    I can't open your GS file at the moment, but if I'm understanding correctly:

    I would make a real attribute called HeroY.
    On the hero actor I would constrain HeroY to self.position.Y
    On the enemy actor I would make a rule:
    Is self.position.y != (is not) HeroY, DO NOT CHASE

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879

    Right now you are testing to see if the distance is less than 300. If you tighten it up just a little and instead test for a distance of less than 250, it will work.

  • quinn221quinn221 Member Posts: 280

    @RThurman said:
    Right now you are testing to see if the distance is less than 300. If you tighten it up just a little and instead test for a distance of less than 250, it will work.

    I changed it to 250 and it still happens

  • NNterprisesNNterprises Member, PRO Posts: 387

    @quinn221 said:

    @RThurman said:
    Right now you are testing to see if the distance is less than 300. If you tighten it up just a little and instead test for a distance of less than 250, it will work.

    I changed it to 250 and it still happens

    Less than 250?

  • quinn221quinn221 Member Posts: 280

    @NNterprises said:
    I can't open your GS file at the moment, but if I'm understanding correctly:

    I would make a real attribute called HeroY.
    On the hero actor I would constrain HeroY to self.position.Y
    On the enemy actor I would make a rule:
    Is self.position.y != (is not) HeroY, DO NOT CHASE

    Thanks...but still happens

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879

    @quinn221 said:
    I changed it to 250 and it still happens

    Oh... I just realized you are referring to its behavior on the ladder. What do you want it to do? At the top of the upper ladder, the hero is still only 238 pixels from the enemy.

    I guess just keep adjusting the number downwards till it gets the behavior you want. For example -- try <200.

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772

    Here is an update. I updated the attack group of behaviors, added another condition that checks to make sure the player and enemy are on the same base line/floor. It follows what @NNterprises mentions but needed adjustments because your player and enemy are different sizes.

  • quinn221quinn221 Member Posts: 280

    @jamie_c said:
    Here is an update. I updated the attack group of behaviors, added another condition that checks to make sure the player and enemy are on the same base line/floor. It follows what @NNterprises mentions but needed adjustments because your player and enemy are different sizes.

    Thanks Jamie!

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772

    You're welcome. Be warned though it's a big tricky, if the enemy and player are not on exactly the same baseline the enemy will not attack. Even 1 pixel makes a difference.

  • quinn221quinn221 Member Posts: 280

    @jamie_c said:
    You're welcome. Be warned though it's a big tricky, if the enemy and player are not on exactly the same baseline the enemy will not attack. Even 1 pixel makes a difference.

    Ok Thanks!

  • quinn221quinn221 Member Posts: 280

    @jamie_c said:
    You're welcome. Be warned though it's a big tricky, if the enemy and player are not on exactly the same baseline the enemy will not attack. Even 1 pixel makes a difference.

    I see what you mean, what is the best way to handle it or set my enemies up on the scene.

  • quinn221quinn221 Member Posts: 280

    @jamie_c said:
    Here is an update. I updated the attack group of behaviors, added another condition that checks to make sure the player and enemy are on the same base line/floor. It follows what @NNterprises mentions but needed adjustments because your player and enemy are different sizes.

    How did you come up with the +48? Is there a formula to use if the enemy are different sizes?

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772

    @quinn221, an updated project is attached. I've updated the enemies attack rule so there is some leeway (100 pixels above and below the players Y Position). You can adjust the 100 to whatever works for your game/enemies.

  • quinn221quinn221 Member Posts: 280

    @jamie_c said:
    @quinn221, an updated project is attached. I've updated the enemies attack rule so there is some leeway (100 pixels above and below the players Y Position). You can adjust the 100 to whatever works for your game/enemies.

    you are a rockstar!

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772

    Looks like you've got a nice game going, hope it works out well! :)

  • quinn221quinn221 Member Posts: 280

    @jamie_c said:
    Looks like you've got a nice game going, hope it works out well! :)

    Thanks, I have been working on it for about 7 months....and not even close to being done. It is going to be a platform and a topdown game. Thanks for all your help!

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
  • jacobpitney77jacobpitney77 Member Posts: 2

    Wow! This is just like the game I was thinking about making. I still need to learn most of Gamesalad, but this game should be a quick finish for what I want to do with it!

  • quinn221quinn221 Member Posts: 280

    @jamie_c Hey Jamie, wondering if you can revisit something on this post. Here is a link for the dropbox file

    https://www.dropbox.com/sh/jz38y1g6l9p3fyr/AAAOxADnAtYdXM8HlhmyKiTga?dl=0

    Here is what I have going on. I am using your logic for an enemy chasing the hero by constraining the self distance to to magnitude(( self.Position.X - game.playerX),(self.Position.Y-game.playerY)) And It works great, but I have noticed once the hero touches the enemy and the hero stops moving... the enemy will stop and not move again until the hero is out of the range again.... I hope I am explaining the right.... anyway if you download the file then, have the hero touch the enemy and stop...then move again you will see what I mean.

    Can you offer a solution? I have been stumped on this for quite a while.

    Thanks.... Cant believe it has been over a year since I started working on this game!

  • greywolfxgreywolfx Member, PRO Posts: 24

    Create a boolean self attribute in your enemy actors and check it as true. when enemy collides with hero, change that self attribute to false. then use a timer to say after 1 sec change self attribute to true. now also add that condition(new self attribute = true) to the rule that chases hero. This should produce the results of every time they collide 1 sec. later the enemy will be told to act on the rule you want. Using a second or 3rd attribute in situations that call for multi actions can help to call for the next action you want to see more reliably. hope that helps :)

  • quinn221quinn221 Member Posts: 280

    @greywolfx thanks..works perfect!!!

    @greywolfx said:
    Create a boolean self attribute in your enemy actors and check it as true. when enemy collides with hero, change that self attribute to false. then use a timer to say after 1 sec change self attribute to true. now also add that condition(new self attribute = true) to the rule that chases hero. This should produce the results of every time they collide 1 sec. later the enemy will be told to act on the rule you want. Using a second or 3rd attribute in situations that call for multi actions can help to call for the next action you want to see more reliably. hope that helps :)

Sign In or Register to comment.