Better movement working. still wip.

This commit is contained in:
Dustin 2025-04-29 00:19:24 -07:00
parent 7421991e56
commit ec869ed1cc
3 changed files with 21 additions and 10 deletions

View File

@ -220,6 +220,14 @@ func new_move_actor_as_desired(_delta :float,
## If there is currently no inertia apply the base h_speed
if calc_inertia.x == 0.0:
calc_inertia.x = h_speed.x
elif calc_inertia.x != 0.0:
if h_speed.x < h_speed.y:
if calc_inertia.x < h_speed.x and sign(move_direction.x) == calc_inertial_dir.x:
calc_inertia.x = h_speed.x
elif h_speed.x > h_speed.y:
if calc_inertia.x > h_speed.x and sign(move_direction.x) == calc_inertial_dir.x:
calc_inertia.x = h_speed.x
## Apply acceleration
calc_inertia.x = move_toward(calc_inertia.x, h_speed.y, abs(calc_acceleration.x * _delta))
## Apply friction
@ -238,20 +246,23 @@ func new_move_actor_as_desired(_delta :float,
elif calc_inertia.x != 0.0: ## We still have inertia but no difference in movement
if calc_acceleration.x != 0.0: # We are applying acceleration
## Move back towards the base speed
if calc_inertia.x < h_speed.x:
calc_inertia.x = clamp( calc_inertia.x + ( calc_acceleration.x * _delta),
calc_inertia.x, h_speed.x)
else:
calc_inertia.x = clamp( calc_inertia.x + ( calc_acceleration.x * _delta),
h_speed.x, calc_inertia.x)
calc_inertia.x = move_toward(calc_inertia.x, h_speed.x, abs(calc_acceleration.x * _delta))
## This was working but trying to simplify with just move_toward
# if calc_inertia.x < h_speed.x:
# calc_inertia.x = clamp( calc_inertia.x + ( calc_acceleration.x * _delta),
# calc_inertia.x, h_speed.x)
# else:
# calc_inertia.x = clamp( calc_inertia.x + ( calc_acceleration.x * _delta),
# h_speed.x, calc_inertia.x)
else: ## No longer applying acceleration
## Neutralize the inertia? but how?
## Recalc the acceleration with inertia
#var friction :Vector2
calc_friction.x = resolve_h_acceleration(movement_params,Vector2(calc_inertia.x, h_speed.x), move_direction.x)
if calc_friction.x != 0.0: ## No dapening acceleration applies
calc_inertia.x = move_toward(calc_inertia.x, h_speed.x, ( calc_friction.x * _delta))
#calc_inertia.x = move_toward(calc_inertia.x, h_speed.x, ( calc_friction.x * _delta))
## Apply friction
calc_inertia.x = move_toward(calc_inertia.x, 0, abs(calc_friction.x * _delta))
else:
## no residual acceleration (friction) applies, kill the momentum
calc_inertia.x = 0.0

View File

@ -10,7 +10,7 @@ debug_state = false
timeout_seconds = 0.0
name = "idle"
horizontal_speed = 1.36422e-12
horizontal_acceleration = -2.0
horizontal_acceleration = -60.0
horizontal_speed_offset = 0.0
horizontal_speed_offset_acceleration = 0.0
jerk_factor = 0.0

View File

@ -10,7 +10,7 @@ debug_state = false
timeout_seconds = 0.0
name = "move"
horizontal_speed = 10.0
horizontal_acceleration = 20.0
horizontal_acceleration = 70.0
horizontal_speed_offset = 80.0
horizontal_speed_offset_acceleration = 0.0
jerk_factor = 0.0