So i'll break down what the snippet is doing piece by piece just to be sure were on the same page, then i'll try and explain what's going wrong.
So this was the snippet you gave:
Code:
if (distance_to_point(obj_player.x,obj_player.y) > 200)
{
move_towards_point(obj_player.xprevious,obj_player.yprevious, 5);
}
if (distance_to_point(obj_player.xprevious, obj_player.yprevious) < 1)
{
spd=0;
}
So this first part:
Code:
if (distance_to_point(obj_player.x,obj_player.y) > 200)
{
move_towards_point(obj_player.xprevious,obj_player.yprevious, 5);
}
Is checking if distance between the object and the point (in this case, the position of the player) is greater than 200. If so, move towards the previous position at a constant speed of 5.
This second part:
Code:
if (distance_to_point(obj_player.xprevious, obj_player.yprevious) < 1)
{
spd=0;
}
Is checking if the distance is less than 1, there it assigns the variable "spd" to 0.
Now, It's important to say, the way it's currently setup, the object will be constantly moving towards the player at a speed of 5. Something i'd recommend, is using a variable for speed. We can use the one that your already using since it's being assigned, but not used.
So my first change will be with the move towards function. For the sake of simplicity, well have that be constantly on and remove the condition, while also changing the value 5 with "spd".
Code:
//always try to move towards player
move_towards_point(obj_player.xprevious,obj_player.yprevious, spd);
Simple enough right? We'll be instead using the condition to change the speed of the object. So basically, it's always trying to move towards the player, but it won't actually move unless its a certain distance away.
Like this:
Code:
//always try to move towards player
move_towards_point(obj_player.xprevious,obj_player.yprevious, spd);
//set the speed of object
if (distance_to_point(obj_player.x,obj_player.y) > 200) // if it's farther than 200 pixels away from player...
{
spd=5;
}
else // if it's closer than 200 pixels...
{
spd=0;
}
The else statement is basically if the opposite of the if statement is happening, then do whatever in the block (or set of brackets).
I should also say that xprevious and yprevious are just the values from the previous step. Kinda hard to explain beyond that.
As you learn more about game maker and GML, you'll learn why this isn't the best method for handling this, but it should still work.
Best of luck! If I need to explain something better please let me know.