Godot Version
4.3
Question
Hi guys
need a bit help here, my character’s movement behaviour is very weird here
in the video, I always only press one button at a time (W, A, S, D) but as seen in the vid, somehow if I change direction (from vertical to horizontal) it will kind of ‘drift’ a little bit
anyone know the solution to the issue?
this is the recording of that weird movement
this is the link to the project
this is the code controlling the movement
func get_movement_vector() -> Vector2:
var x_movement = Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
var y_movement = Input.get_action_strength("move_down") - Input.get_action_strength("move_up")
return Vector2(x_movement, y_movement)
and this is where the movement take place
func physics_update(delta: float) -> void:
# get movement direction
var movement_vector = movement_component.get_movement_vector()
var direction = movement_vector.normalized()
# Apply movement direction
var target_velocity = direction * MAX_SPEED
parent.velocity = parent.velocity.lerp(target_velocity, 1 - exp(-delta * ACCELERATION_SMOOTHING))
parent.move_and_slide()
# check if should transition to other state
if movement_vector.x == 0 and movement_vector.y == 0:
transaitioned.emit(self, Constants.State.IDLE)