I am trying to make a smooth grid-based 3d movement(Legend of Grimrock 2 for the reference) and I am using lerp to set player's position but it has unpleasant delay at the end; Is there any way to make it more responsive
Here is my movement script
extends Node3D
const SPEED = 15.
var new_pos: Vector3 = Vector3.ZERO
var moving: bool = false
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
var cellpos = %Map.map_to_local(Vector3i(0,0,0))
position = cellpos
new_pos = position
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
if moving:
position = position.lerp(new_pos, delta * SPEED)
if position.is_equal_approx(new_pos):
moving = false
func _input(event: InputEvent) -> void:
handle_movement(event)
func handle_movement(event: InputEvent) -> void:
if moving:
return
if event.is_action_pressed("forward"):
new_pos = Vector3(position.x, position.y, position.z + %Map.cell_size.z)
if event.is_action_pressed("backward"):
new_pos = Vector3(position.x, position.y, position.z - %Map.cell_size.z)
if event.is_action_pressed("left"):
new_pos = Vector3(position.x + %Map.cell_size.x, position.y, position.z)
if event.is_action_pressed("right"):
new_pos = Vector3(position.x - %Map.cell_size.x, position.y, position.z)
moving = true
%Map is a GridMap object
also attached the video which shows that movement is set to false with very big delay even so player has already stopped moving