GameMaker Studio 2 Follow Player Smoothly

Example:

As we can see, the key and the owl follow the player.

Here’s the code:

 

if (instance_exists(oPlayer)) {

    if(oPlayer.x >= x){
        image_xscale = 1;
        x += (oPlayer.x-10 – x) * 0.04
       y += (oPlayer.y-15 – y) * 0.04
    }else{
        image_xscale = -1;
        x += (oPlayer.x+10 – x) * 0.04
        y += (oPlayer.y-15 – y) * 0.04
    }
}

More Posts

Send Us A Message

GameMaker Studio 2 Follow Player Smoothly

More Posts

Send Us A Message