Hi,
I've got a player object and an enemy object.
I want the enemy to move towards the player when within a certain range and then stop when out of range.
This is the code I have:
if (instance_exists(oPlayer))
{
if (distance_to_object(oPlayer)< 100)
{
move_towards_point(oPlayer.x,oPlayer.y, spd)
}
else
{
spd=0;
}
}
When I add the 'else' the enemy object doesn't move at all no matter how close I am.
Can somebody tell me what I'm doing wrong or if there is a better way of doing this?
Thanks,
Tom
I've got a player object and an enemy object.
I want the enemy to move towards the player when within a certain range and then stop when out of range.
This is the code I have:
if (instance_exists(oPlayer))
{
if (distance_to_object(oPlayer)< 100)
{
move_towards_point(oPlayer.x,oPlayer.y, spd)
}
else
{
spd=0;
}
}
When I add the 'else' the enemy object doesn't move at all no matter how close I am.
Can somebody tell me what I'm doing wrong or if there is a better way of doing this?
Thanks,
Tom