GameSalad

enemy follow player

emojiemoji Posts: 11Member, PRO

Hello, I'm trying to make my enemy follow my player but for some reason, the player just goes left and right. I have declared two variable of xPos and yPos and assign it to player position. attach is my enemy setting. It is supposed
to follow my player but it not. can someone please assist me. thank very much.

Comments

  • AlchimiaStudiosAlchimiaStudios Posts: 942Member, PRO
    edited July 12

    @emoji

    Accelerate toward will ramp up the acceleration and only turn it down once the x and y are reached, but because the acceleration is still in effect it will go past it, then it retriggers and continues to do that, forever.

    It's better to do the following:

    rule when all the follow are happening:

    if attribute self.position.x != game.posX

    do:

    move to game.posX / game.posY

    Also make sure you are using constrains on the player actor so

    constrain game.posX to self.position.x

    constrain game.posY to self.position.y

    Follow us: Twitter - Website

  • emojiemoji Posts: 11Member, PRO

    update, in my player setting, how come this global variable xPos and yPos does not change when my player moving?

  • AlchimiaStudiosAlchimiaStudios Posts: 942Member, PRO

    See above. Make sure you're using constrains.

    Follow us: Twitter - Website

  • emojiemoji Posts: 11Member, PRO

    I got it working. thank you a lot.

Sign In or Register to comment.