GameSalad

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Advanced enemy following

brett-nortonbrett-norton Posts: 64Member, BASIC

Hi All hope your well.

Im trying to code a few problem obstacles in my game kind of advanced following / move too. (Advanced for me anyway)

Things i need to consider i have a 2d platformer type level. With 3 floors ladders connecting to each. I have the ladders to the sides of the entrance and exit facing sideways to prevent having to animate a rear view to my character. A side view climbing looks ok.

I have random enemys spawning at random spots and moving toward the player could be in a different area on a different floor.

Im using the if enemy actor player location is > more left and if < move right which now works fine when both enemy and player on the same floor.

Im struggling to think of the best way to get an enemy to moving to a player that could be 2 floors below and needs to move right and left to get to the next set of ladders.

Im thinking have an attribute for each floor and a path to follow to that floor. Or if player is above enemy move to nearest ladder.

Just some clarity would be great.

Comments

  • ToqueToque Posts: 1,181Member
    edited May 2017

    Lost me in the last two paragraphs.

    You want the enemy to go to a ladder and move to current players floor?? And then chase him again both on same floor??

  • brett-nortonbrett-norton Posts: 64Member, BASIC

    Yes mate.. so with the move rule i mentioned previously works fine when they are on the same floor.. but if the enemy is 2 floors below for example he would just sit below me and follow my x location 2 floors below.

    I need the enemy to move to the ladders and reach the floors above and get the the floor the player is on and then continue with the move to behavior.

    Also the opposite will be needed if the enemys spawns above and player is on floors below.

  • brett-nortonbrett-norton Posts: 64Member, BASIC

    That make sense?

  • IceboxIcebox Posts: 1,483Member
    edited May 2017

    @brett-norton said:
    Yes mate.. so with the move rule i mentioned previously works fine when they are on the same floor.. but if the enemy is 2 floors below for example he would just sit below me and follow my x location 2 floors below.

    I need the enemy to move to the ladders and reach the floors above and get the the floor the player is on and then continue with the move to behavior.

    You can add a condition in the enemy actor
    if self.position.y > game.playerY -30 and
    self.position.y < game.player y +30 ( 30 is just a random number , test depending on your game)
    then move to x location of player

    so the enemy will only move if its y position is at the same level of the players y position.

  • ToqueToque Posts: 1,181Member
    edited May 2017

    I guess if they are not on same level I would set rule for the enemy to go to a ladder then not go to the player.

    Have Enemy climb to player level and only have enemy chase player position x if they are on same level.

    So enemy only chase ladders when not on same level.

    Enemy chase player if on same level with player.

  • brett-nortonbrett-norton Posts: 64Member, BASIC

    Finally cracked it thanks guys.

Sign In or Register to comment.