Moving enemies toward the player in a 2d side scrolling platform/beat'em up
Toecutter
Member Posts: 19
I'm struggling to make the enemies in my game move toward the player/hero. Tried a number of things each with unexpected (and unwanted) results!
Basically I want the enemy to move toward the player if the player is with a certain range along a horizontal 2d plane, walking along the ground. Also the enemy needs to face the player and use a walking animation (I think I've solved that part).
I'm using the windows beta.
I've tried 2 different ways, the first makes the enemy move toward the player and it animates but it floats around like an astronaut.
The other just locks the enemy into the bottom left corner (see picture) but does animate and react to the players direction.
Any help would be great. Thanks!
http://i1114.photobucket.com/albums/k539/toecutter78/fkr_zpsce893824.png
Basically I want the enemy to move toward the player if the player is with a certain range along a horizontal 2d plane, walking along the ground. Also the enemy needs to face the player and use a walking animation (I think I've solved that part).
I'm using the windows beta.
I've tried 2 different ways, the first makes the enemy move toward the player and it animates but it floats around like an astronaut.
The other just locks the enemy into the bottom left corner (see picture) but does animate and react to the players direction.
Any help would be great. Thanks!
http://i1114.photobucket.com/albums/k539/toecutter78/fkr_zpsce893824.png
Answers
For moving towards the Hero Actor, are you using Gravity (or any other Physics)? How're the Equations you are using? Maybe you can indicate how you did it the first 2 times. I have experienced something similar a while back but can't remember the solution -- however, I do use Cos/Sin to move in circles and fly.. like an astronaut floating into space.
For detecting Range, I suggest going through this thread I created a while back. Scroll down until you see Darren's post (DeepBlueApps) and check out his explanation. Should solve this for you.
I've used 2 real attributes (characterX & characterY) to identify my heroes position and another 2 real attributes (enemyx & enemyY) to identify the enemies position. I also has another real attribute: distancetohero.
My hero has 2 constrain attributes:
constrain:self.position.x to: game.characterx and the same for the Y axis
The enemy has:
Constrain Attribute:
Constrain: game.distancetohero to: magnitude(game.characterx-self.positionx-game.characterY-game.characterY-self.position.Y)
Change attribute
set:game.characterx to:self.position.x
and another change attribute doing the same thing for the Y
For a direction:
Rule
When all
Attribute
if:distancetohero < 150
do:
move to: game.characterx moveto: game.characterY
at speed 150
else
move to
self.startX self.start.y
speed:150
With this the enemy just flys towards my hero, but I need it to walk along the ground towards the hero. Platforms to walk on are in tags. Also alot of the time the enemy just gets stuck to one spot.
it has to be magnitude(game.characterx-self.position.X, game.charactery-self.position.Y
I think...
✮ FREE templates at GSinvention ✮
✮ Available for hire! support@gsinvention.com ✮
✮ FREE templates at GSinvention ✮
✮ Available for hire! support@gsinvention.com ✮
magnitude(game.characterx-self.positionx, game.characterY-self.position.Y)