Does anyone have a basic routine for the patrol enemy behavior of a platform game?

0 favourites
From the Asset Store
A pack of 76 platform designs for a platformer game with a mushroom/jungle theme
  • Remember: I still using C2, guys. ^^

  • Lionz’ suggestion is by far the easiest. Just put invisible sprites on the edges of the platforms, and have the enemy change direction when colliding with them.

    If it’s too laborious to place the sprites then there is likely a way to automate placing them, but it depends how you make your platforms.

    Another way could be to detect the edges of the platform with a small detector sprite. Say the enemy is moving right. Move the detector sprite to the bottom right corner of the enemy. If the detector isn’t overlapping a platform the change the enemy direction to left. You’d do similar logic for moving left. You could also use “pick overlapping point” instead of a small detector sprite.

    A third way could be just to pick the platform the enemy is on and change direction when getting close to the edge. Would work well if the platform is just one long object. Logic for the right edge would be the following. Left edge is similar.

    For each enemy

    Enemy overlaps platform at offset(0,1)

    Enemy: is moving right

    Compare: enemy.bboxright>platform.bboxright

    — enemy: set direction to left

    Fourth way would be to just use the sine behavior to move the enemy. Place the enemy at the center of the platform, set the magnitude to half the platform width, set motion to horizontal and wave to triangle. I’m unsure if position would drift over time though with different frame rates.

    There are probably many other possible solutions.

  • For tiles platforms, you can simply use the Tilemap expressions to detect if the enemy has reached the end of any platform. And, for sprites platforms, you can easily compare the coordinates of the enemy and the platform, this will work even with mobile platforms.

    Check this: fileport.io/tyaTYhsxL2Ae

  • Lionz’ suggestion is by far the easiest. Just put invisible sprites on the edges of the platforms, and have the enemy change direction when colliding with them.

    If it’s too laborious to place the sprites then there is likely a way to automate placing them, but it depends how you make your platforms.

    Another way could be to detect the edges of the platform with a small detector sprite. Say the enemy is moving right. Move the detector sprite to the bottom right corner of the enemy. If the detector isn’t overlapping a platform the change the enemy direction to left. You’d do similar logic for moving left. You could also use “pick overlapping point” instead of a small detector sprite.

    A third way could be just to pick the platform the enemy is on and change direction when getting close to the edge. Would work well if the platform is just one long object. Logic for the right edge would be the following. Left edge is similar.

    For each enemy

    Enemy overlaps platform at offset(0,1)

    Enemy: is moving right

    Compare: enemy.bboxright>platform.bboxright

    — enemy: set direction to left

    Fourth way would be to just use the sine behavior to move the enemy. Place the enemy at the center of the platform, set the magnitude to half the platform width, set motion to horizontal and wave to triangle. I’m unsure if position would drift over time though with different frame rates.

    There are probably many other possible solutions.

    Thanks, Rojo! I'll test your suggestions later.

    You´re always saving the day! :D

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • For tiles platforms, you can simply use the Tilemap expressions to detect if the enemy has reached the end of any platform. And, for sprites platforms, you can easily compare the coordinates of the enemy and the platform, this will work even with mobile platforms.

    Check this: fileport.io/tyaTYhsxL2Ae

    Thanks again, dude!

    You did too much here!

Jump to:
Order by:
Duplicate Topics
Posts
Views
Last Post
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)