The issue I'm having is in the following video, you can see that while moving there is a stutter, and in a single tile movement I move 1 pixel past the target position before jumping back to the target. I was wondering if anyone knows why or how to fix this (I'm pretty sure this is due to the await function being time based).
My movement code looks like this,
const EPSILON = .00001
const Tile_Size: int = 16
func move (target_pos: Vector2 , delta):
is_moving = true
while (target_pos - position).length() > EPSILON:
position.x = move_toward(position.x, target_pos.x, move_speed * delta)
position.y = move_toward(position.y, target_pos.y, move_speed * delta)
await get_tree().create_timer(delta).timeout
position = target_pos
is_moving = false
And is called here:
if (input != Vector2.ZERO):
var target_pos = position;
target_pos.x += input.x * Tile_Size
target_pos.y += input.y * Tile_Size
move(target_pos,delta)
using this as the input:
if Input.is_action_pressed(key):
if key == "ui_right":
input.x = 1
input.y = 0
elif key == "ui_left":
input.x = -1
input.y = 0
elif key == "ui_down":
input.x = 0
input.y = 1
elif key == "ui_up":
input.x = 0
input.y = -1
else:
input = Vector2.ZERO