how do I make a key follow the player without it randomly moving? Help!

L

lachlantopcat games

Guest
so I'm making a game that has keys in it and when thay follow you thay can get stuck and thay randomly move
the key will move randomly when the player is standing still.



the code:

Code:
//move to the player

if (instance_exists(obj_player)){
   mp_potential_step(obj_player.x, obj_player.y, 10, false);
}

//player attacking follow

if (instance_exists(obj_atackr)){
   mp_potential_step(obj_atackr.x, obj_atackr.y, 10, false);
}
 

TheouAegis

Member
You need to check if the distance to the player is greater than 10. That 10 in your code is how far the key will move each step. If the key is less than 10 pixels away when it moves, then it will move to the other side of the player. Then on the next step it will move back. So if the key's distance is greater than 10, move toward the player, otherwise don't move.
 
Top