Enemy Chase
quinn221
Member Posts: 280
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
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
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?
Thanks...but 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.
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.
http://jamie-cross.net/posts/ ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad ✮ My Patreon Page
Thanks Jamie!
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.
http://jamie-cross.net/posts/ ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad ✮ My Patreon Page
Ok Thanks!
I see what you mean, what is the best way to handle it or set my enemies up on the scene.
How did you come up with the +48? Is there a formula to use if the enemy are different sizes?
@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.
http://jamie-cross.net/posts/ ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad ✮ My Patreon Page
you are a rockstar!
Looks like you've got a nice game going, hope it works out well!
http://jamie-cross.net/posts/ ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad ✮ My Patreon Page
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!
You're welcome, keep us posted on the progress.
http://jamie-cross.net/posts/ ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad ✮ My Patreon Page
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!
@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!
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
@greywolfx thanks..works perfect!!!