Getting better on movement but still buggy.

This commit is contained in:
Dustin 2025-04-26 13:36:17 -07:00
parent 633881ede8
commit dceb0ad3e8
2 changed files with 49 additions and 31 deletions

View File

@ -144,6 +144,8 @@ func _on_state_change(old_state_name:String, new_state :State):
# Update: Actually should just return movement in PPS
##
var calc_inertia = velocity.abs()
var calc_inertial_dir :Vector2
var debug_speed_tracker :Vector2
func new_move_actor_as_desired(_delta :float,
_state :StateAnimatedActor,
_movement_override_normal := Vector2(0,0)) -> Vector2:
@ -174,16 +176,15 @@ func new_move_actor_as_desired(_delta :float,
## If an override has been passed (we're ignoring input direction
var move_direction = Vector2.ZERO
if _movement_override_normal != Vector2.ZERO:
move_direction = resolve_move_direction(inertia, _movement_override_normal)
move_direction = resolve_move_direction(calc_inertial_dir, _movement_override_normal)
else:
move_direction = resolve_move_direction(inertia, desired_movement_vector)
move_direction = resolve_move_direction(calc_inertial_dir, desired_movement_vector)
calc_acceleration.x = resolve_h_acceleration(movement_params, h_speed, move_direction.x)
if calc_acceleration.x != 0:
acceleration.x = calc_acceleration.x
## if we have a difference of speed
if h_speed.x != h_speed.y:
debug_speed_tracker = h_speed
if calc_inertia.x == 0.0:
#calc_inertia.x = lerp( h_speed.x , h_speed.y, calc_acceleration.x * _delta)
calc_inertia.x = clamp( calc_inertia.x + (calc_acceleration.x * _delta),
@ -192,34 +193,49 @@ func new_move_actor_as_desired(_delta :float,
#calc_inertia.x = lerp( calc_inertia.x, h_speed.y, calc_acceleration.x * _delta)
calc_inertia.x = clamp( calc_inertia.x + ( calc_acceleration.x * _delta),
calc_inertia.x, h_speed.y)
elif calc_inertia.x != 0.0:
## We still have inertia
#calc_inertia.x = lerp(calc_inertia.x, h_speed.x, _delta)
calc_inertia.x = clamp( calc_inertia.x + ( acceleration.x * _delta),
calc_inertia.x, h_speed.x)
# if (current_state.name == 'idle'):
# print(acceleration)
elif calc_inertia.x != 0.0: ## We still have inertia
if calc_acceleration.x != 0.0: # We are applying acceleration
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
friction.x = resolve_h_acceleration(movement_params,Vector2(calc_inertia.x, h_speed.x), move_direction.x)
if friction.x != 0.0: ## No dapening acceleration applies
if calc_inertia.x > h_speed.x: ## Inertia is higher than the base speed (slow it down)
calc_inertia.x = clamp( calc_inertia.x + ( friction.x * _delta),
h_speed.x, calc_inertia.x)
else: ## Inertia lower than base speed (we need to catch up)
calc_inertia.x = clamp( calc_inertia.x + ( friction.x * _delta),
calc_inertia.x, h_speed.x)
else:
## no residual acceleration (friction) applies, kill the momentum
calc_inertia.x = 0.0
if (h_speed != debug_speed_tracker):
print("Inertia SpeedShift: ", debug_speed_tracker, h_speed, (0.0 == -0.0))
debug_speed_tracker = h_speed
else:
## inertia is just base speed
calc_inertia.x = h_speed.x
acceleration = Vector2.ZERO
#calc_acceleration.x = resolve_h_acceleration(movement_params, h_speed, move_direction.x)
## One idea, pass all the calculations independently
# var movement = {
# "velocity_PPS" : calc_velocity,
# "acceleration_PPS" : calc_acceleration,
# "inertia_PPS" : calc_inertia
# }
## Another idea, just return the calculated velocity in PPS
## calc x component of felicty
## For now, y component of velocity is just gravity
calc_velocity.y = movement_params["_gravity"] * Vector2.DOWN.y
calc_velocity.x = calc_inertia.x * move_direction.x
## calc x component of felicty
if calc_inertial_dir.x != 0:
calc_velocity.x = calc_inertia.x * calc_inertial_dir.x
else:
calc_velocity.x = calc_inertia.x * move_direction.x
calc_inertial_dir = Vector2(sign(calc_velocity.x),sign(calc_velocity.y))
UiManager.debug_text = ( #"H_Speed x Dir: " + str(h_speed) + str('duh') +
"H_Speed: {0}, {1}".format({"0":"%5.2f" % h_speed.x, "1":"%5.2f" % h_speed.y}) +
@ -266,13 +282,15 @@ func resolve_h_acceleration(_params :Dictionary, _speed :Vector2, _move_directio
var _acceleration :float = 0.0
if _params["_base_h_move_speed_modifier"] != 0:
_acceleration = _params["_base_h_move_acceleration"] + _params["_base_h_move_modifier_move_acceleration"]
# if sign(_acceleration) == sign(_move_direction):
# return _acceleration
# elif _move_direction == 0:
# return _acceleration * -1
else:
_acceleration = _params["_base_h_move_acceleration"]
## Well this didn't work
#_acceleration = _params["_base_h_move_acceleration"] + _params["_base_h_move_modifier_move_acceleration"]
if _speed.x < _speed.y:
return _acceleration
else:
elif _speed.x > _speed.y:
return _acceleration * -1
return 0.0

View File

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