T
Toomuchbob
Guest
Code:
/// @description Player is moving
//clamp x
if (x == clamp(x, target_x - 0.5, target_x)) {
x = floor(target_x);
} else {
show_debug_message(target_x);
x = lerp(x, target_x, .125);
}
//clamp y
if (y == clamp(y, target_y - 0.5, target_y)) {
y = floor(target_y);
} else {
show_debug_message(target_y);
y = lerp(y, target_y, .125);
}
//clamp direction
if (dir < target_dir) {
if (dir == clamp(dir, target_dir - 1, target_dir)) {
dir = floor(target_dir);
} else {
show_debug_message(target_dir);
dir = lerp(dir, target_dir, .125);
}
} else {
if (dir == clamp(dir, target_dir, target_dir + 1)) {
dir = floor(target_dir);
} else {
show_debug_message(target_dir);
dir = lerp(dir, target_dir, .125);
}
}
//set player state
if (x == target_x and y == target_y and dir == target_dir) {
_playerController.state = playerIdle;
} else {
_playerController.state = playerMoving;
}