From dff822c6f4146047175fc558d54905396fc01033 Mon Sep 17 00:00:00 2001 From: Dustin Date: Mon, 28 Apr 2025 20:10:15 -0700 Subject: [PATCH] reintroduce calc_velocity variable, allow override for testing. --- lib/classes/movement_state_receiver.gd | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/classes/movement_state_receiver.gd b/lib/classes/movement_state_receiver.gd index 47584ae..67d0f50 100644 --- a/lib/classes/movement_state_receiver.gd +++ b/lib/classes/movement_state_receiver.gd @@ -158,17 +158,21 @@ func new_move_actor_as_desired(_delta :float, "_gravity" : _state.gravity } var calc_velocity = Vector2.ZERO + if _velocity_override.x != 0.0: + calc_velocity.x = _velocity_override.x + else: + calc_velocity.x = velocity.x + if _velocity_override.y != 0.0: + calc_velocity.y = _velocity_override.y + else: + calc_velocity.y = velocity.y + var calc_acceleration = Vector2.ZERO var calc_inertia :Vector2 - ##TODO: make sure velocity variable exists since we rely on it - ## Calc from the _velocity_override instead of current object velocity - if _velocity_override.x != 0.0: - calc_inertia.x = abs(_velocity_override.x) - else: - calc_inertia.x = abs(velocity.x) - ##TODO: Only implemented horizontal so far. - calc_inertia.y = velocity.y - var calc_inertial_dir = Vector2(sign(velocity.x),sign(velocity.y)) + calc_inertia.x = abs(calc_velocity.x) + calc_inertia.y = calc_velocity.y + + var calc_inertial_dir = Vector2(sign(calc_velocity.x),sign(calc_velocity.y)) var calc_friction :Vector2 = Vector2.ZERO ## Inertia only applies if there is a difference between the @@ -188,7 +192,7 @@ func new_move_actor_as_desired(_delta :float, move_direction = resolve_move_direction(calc_inertial_dir, desired_movement_vector) ## Which direction will acceleration be applied. - calc_acceleration.x = resolve_h_acceleration(movement_params, velocity, move_direction.x) + calc_acceleration.x = resolve_h_acceleration(movement_params, calc_velocity, move_direction.x) ## Direction of inertia not equal to move direction ## If inertia is applying in a direction