How do I make an enemy pace and stop?

0 favourites
  • 6 posts
From the Asset Store
Give Sound to the enemies that are part of your game! :)
  • got an enemy with a platform behavior and i want him to jump at random intervals (which works fine and was easy to get right) and also to walk forward or backwards for about half a second at different, also random intervals. thing is, setting him to move "every x seconds" will only input that control for one frame. any thoughts on how i can sustain that movement long enough to matter, but also have him stop in between and not just go from left to right?

  • You can simulate left/right whilst a boolean is enabled then switch it off, or you could make use of rexrainbow moveto plugin.

  • got an enemy with a platform behavior and i want him to jump at random intervals (which works fine and was easy to get right) and also to walk forward or backwards for about half a second at different, also random intervals. thing is, setting him to move "every x seconds" will only input that control for one frame. any thoughts on how i can sustain that movement long enough to matter, but also have him stop in between and not just go from left to right?

    Ok from your post I am assuming you know how to get the enemy moving left and right but you want him to stop for a moment before turning around.

    Ok basically let say you have an invisible box the your enemy hits to make him move back and forth.

    Collision , with invisiblebox = accelleration=0

    wait(2.0)

    accelleration=1000

    moveleft=1

    moveright=0

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I would recommend learning how to create a "state-machine" (I believe that is what they are called).

    So you would have an instance variable called "state" and depending on what that is corresponds with what he does. Timer behavior would be needed to go along with this.

    Example:

    If state = "right" then simulate right

    If state = "left" then simulate left

    If state = "idle" then idle animation

    On Timer

    -state = "left" or "right" then state = "idle"

    -state = "idle"

    --Choose(0, 1) > 0 then state = "left"

    --Else state = "right"

    Restart Timer

    This is the basics, if you want more states then just map out the order that they should move through states. For example one I've done for shooting zombies is idle -> aim -> fire -> recoil -> recover(just a pause) -> idle ... but from idle a different chain can occur such as move, reload, etc.

    Jumping at random intervals can be done as a state or separately with a timer. When setting state to left or right start the state timer and also a jump timer (can set to random time). On timer simulate jump.

    Edit: definitely add the "Else" where applicable in above commands

  • I would recommend learning how to create a "state-machine" (I believe that is what they are called).

    So you would have an instance variable called "state" and depending on what that is corresponds with what he does. Timer behavior would be needed to go along with this.

    Example:

    If state = "right" then simulate right

    If state = "left" then simulate left

    If state = "idle" then idle animation

    On Timer

    -state = "left" or "right" then state = "idle"

    -state = "idle"

    --Choose(0, 1) > 0 then state = "left"

    --Else state = "right"

    Restart Timer

    This is the basics, if you want more states then just map out the order that they should move through states. For example one I've done for shooting zombies is idle -> aim -> fire -> recoil -> recover(just a pause) -> idle ... but from idle a different chain can occur such as move, reload, etc.

    Jumping at random intervals can be done as a state or separately with a timer. When setting state to left or right start the state timer and also a jump timer (can set to random time). On timer simulate jump.

    Edit: definitely add the "Else" where applicable in above commands

    that sounds like the best way to do it, thanks man! pretty much everything i was coming up with last night would've had more regulated movement that i'd like

  • You are welcome!

    ...and I just realize instead of choose(0, 1)... you can just set state = choose("left", "right")

    Let me know if you have any questions

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)