enemy follow player

emojiemoji Member, BASIC Posts: 66

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 Member Posts: 1,069
    edited July 2018

    @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 Member, BASIC Posts: 66

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

  • AlchimiaStudiosAlchimiaStudios Member Posts: 1,069

    See above. Make sure you're using constrains.

    Follow us: Twitter - Website

  • emojiemoji Member, BASIC Posts: 66

    I got it working. thank you a lot.

Sign In or Register to comment.