Make enemy follow Player?

sokarokasokaroka Member Posts: 9
edited November -1 in Working with GS (Mac)
I'm making a game similar to tilt to live on iPhone.

It's a survival game where you must avoid enemies that kill you when you touch them.

I need the enemies to move towards the Player.

Also can you make accelerate stop at a certain speed?
I want them to go towards the player at a speed of 100, not accelerate from 0 - 100, but just go at 100 the whole time.

Wrap up, how can I make the enemy move to the Player position at a set speed of 100?

Comments

  • quantumsheepquantumsheep Member Posts: 8,188
    Constrain the player's X and Y position to new attributes (integer) - PlayerX and PlayerY

    On your enemies have the behaviour:
    Move to Player X, Player Y

    That should do it...

    QS

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

  • danlbryantdanlbryant Member Posts: 236
    I figured this out for my game, It's pretty easy, if you want the enemies to rotate toward the player, you can use the behavior: Rotate to Position. And just set the X and Y to the playerX & playerY variables.
  • sokarokasokaroka Member Posts: 9
    Sorry but how do I do that?

    Do I use the expression editor?
    I tried searching through that but found nothing...
  • sokarokasokaroka Member Posts: 9
    Ok what I think I've done...
    On the player I got a Constrain attribute, setting self.Position.X/Y to PlayerX and PlayerY.
    Then on the enemy I have move to PlayerX, PlayerY.

    But then enemy moves to 0, 0
    Which is the players starting position, so I didn't think it was continuously updating.
    I then put a timer, to make the enemy move to PlayerX, PlayerY every 0.1 seconds, but it still just went to 0, 0 and stopped.

    Please explain for a noob :)

    Also you said just set the X and Y to the players x and y variables...
    How do I do that?
    If I use the expression editor on the enemy, I can't find Player in the "game" directory...
  • sokarokasokaroka Member Posts: 9
    Bump
  • JuggerJugger Member, PRO Posts: 238
    make 2 game attributes

    playersx and playersy both of them type real

    the in your players do this

    timer
    every 2 seconds

    change attribute game.playersx to self.position.x (or Constrain attribute)
    and
    change attribute game.playersy to self.position.y

    then on your bullet do this

    accelerate towards

    game.playersx and game.playersy relative to scene

    ______
    as allways thx to Tshirtbooth :)
  • sokarokasokaroka Member Posts: 9
    Yay thanks alot Jugger, and the rest of you :)

    :D
  • ValanValan Member, BASIC Posts: 410
    Take a look at my game Fireflight.

    The homing missiles, people and boss droids use a timed fast Accelerate to behaviour balanced with a heavy Drag.

    Sorry, need to feed the baby. I'll post a more detailed explanation tomorrow.
Sign In or Register to comment.