GMS 2 made a basic code to get enemy to follow player and this happened

.gif of the bug occuring here:
https://gyazo.com/b8ee699a4b0dca579f87e359f6406e10

this is my code i wrote in the step event of the enemy:

if (instance_exists(obj_player))
{
move_towards_point(obj_player.x, obj_player.y, speed_);
}

only other thing in the enemy object is speed_ = 5; in the create event, I didn't know where to start seeking for help cause the code is so small. Please help!
 

TsukaYuriko

šŸŒ 
Forum Staff
Moderator
That is to be expected - you have nothing in your code that tells it to stop moving if it's close enough to the player... ;)
 

Catastrophe

Member
^ Or if the problem is that it doesn't go right up to the player, I'm assuming your sprite origins are incorrect. If that isn't the issue, we'll need to know more xD
 

TheouAegis

Member
Looks like the player's sprite origin is set WAAAAAAAAAAAAAY off to the left (or right, if the player faces right by default) in empty space, as though the sprite was created by someone that didn't read the manual on sprite creation. :p

What bugs me though is when the player seems to turn around at the end of that animation... Oh well. Fix your origin, then check for bugs again.
 
^ Or if the problem is that it doesn't go right up to the player, I'm assuming your sprite origins are incorrect. If that isn't the issue, we'll need to know more xD
I have the origin in a certain spot to draw my gun on it, is there any way I can make the enemy follow me without screwing up the placement of the gun? thanks!
 

Rob

Member
I think you should keep it as a friendly-but-annoying bot that sometimes says whacky things
 
Couldn't you just use point_distance to figure out if your too far away and if so then follow? Should be as simple as wrapping the move function with an if like this:

if(point_distance(obj_player.x, obj_player.y, x, y) > 10){
move_towards_.....
}
 
Couldn't you just use point_distance to figure out if your too far away and if so then follow? Should be as simple as wrapping the move function with an if like this:

if(point_distance(obj_player.x, obj_player.y, x, y) > 10){
move_towards_.....
}
did this code exactly with my move towards player between the brackets, also MADE SURE my player origin was middle centre and it still happens just a little differently https://gyazo.com/3274a828c9c262ab090b78ec629b7c37
 
fixed it! it was the origin of the enemy
I have the origin in a certain spot to draw my gun on it, is there any way I can make the enemy follow me without screwing up the placement of the gun? thanks!
you were almost right it was the origin of the enemy not the player, thankyou!
 
Top