Enemies when chasing player jitter and shake.

Edvard

Member
When i make an enemy code that follows the player the enemy jitters for some reason. Nothing fixes the problem. Here's my code:
spd = (point_distance(x,y,obj_player.x,obj_player.y)/100);
move_towards_point(obj_player.x,obj_player.y,spd);
 

Edwin

Member
move_towards_point works incorrectly with odd values so I recommend you using this script instead of it:
Code:
/// pass_value(current, target, speed)

// Variables
var c, t, a;

c = argument[0];
t = argument[1];
a = argument[2];

// Script
if (c < t) {
    c = min(c+a, t);
}
else {
    c = max(c-a, t);
}

// Return current value
return c;
Then just use it like this:
Code:
x = pass_value(x, obj_player.x, spd);
y = pass_value(y, obj_player.y, spd);
 
Top