Moving enemies toward the player in a 2d side scrolling platform/beat'em up

ToecutterToecutter Member Posts: 19
edited July 2013 in Working with GS (Mac)
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

Answers

  • TheGabfatherTheGabfather Member Posts: 633
    edited July 2013
    The buggy enemy Actor might be.. bugging.. because of its initial Coordinates. Do you place them in the Scene manually, or do you Spawn them in-game? If you're placing them in there manually, I suggest looking at the X and Y Coordinates, and deleting any decimal values above zero. There's a Windows Creator bug that pushes some Actors to the bottom left hand corner of the screen.

    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.
  • ToecutterToecutter Member Posts: 19
    Thanks for the reply. I'm not using gravity, just commands to move in certain directions.
    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.


  • -Timo--Timo- Member Posts: 2,313

    Constrain: game.distancetohero to: magnitude(game.characterx-self.positionx-game.characterY-game.characterY-self.position.Y)
    I am missing the , :) and there is 1 game.characterY to much
    it has to be magnitude(game.characterx-self.position.X, game.charactery-self.position.Y
    I think...
  • -Timo--Timo- Member Posts: 2,313
    magnitude(game.characterx-self.position.X, game.charactery-self.position.Y)
  • ToecutterToecutter Member Posts: 19
    Sorry thats a typo :P should be ...
    magnitude(game.characterx-self.positionx, game.characterY-self.position.Y)
  • joshiwujoshiwu Member Posts: 207
    edited July 2013
    Turn Drag off(in actor attribute of enemy). and interpolate. still using toe cutter's (x,Y)
Sign In or Register to comment.