• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

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);
 
E

Edwin

Guest
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