Maybe better impulse apply

This commit is contained in:
Dustin 2025-05-04 19:17:08 -07:00
parent f7f5ce1e61
commit 8906b98680
4 changed files with 34 additions and 12 deletions

View File

@ -195,11 +195,11 @@ func new_move_actor_as_desired(_delta :float,
else:
move_direction = resolve_move_direction(calc_inertial_dir, desired_movement_vector)
##TODO: the impulse logic just doesn't work still
if sign(calc_velocity.x) != move_direction.x and sign(calc_velocity.x) != impulse_applied_dir:
print("resetting impulse")
impulse_applied = false
impulse_applied_dir = sign(move_direction.x)
##WIP: the impulse logic just doesn't work still, below is another attempt
# if impulse_applied_dir != move_direction.x and sign(calc_velocity.x) != impulse_applied_dir:
# print("resetting impulse")
# impulse_applied = false
# impulse_applied_dir = sign(move_direction.x)
var modifier_indicator := ''
@ -224,6 +224,13 @@ func new_move_actor_as_desired(_delta :float,
## Speed will now be expected to move in the direction of travel
h_speed *= move_direction.x
## Reset the impulse when back in range
# may also want to reset when hspeed is static
if (is_out_of_range(calc_inertia.x, h_speed.x, h_speed.y) == false and
impulse_applied == true ):
print("resetting impulse")
impulse_applied = false
## We don't want to be able to scoot our impulse speed to cheat the movement
# Any non zero speed that goes opposite to our inertial direction
# should only be allowed once.
@ -272,10 +279,10 @@ func new_move_actor_as_desired(_delta :float,
if is_out_of_range(calc_inertia.x, h_speed.x, h_speed.y) or h_speed != debug_speed_tracker:
## ? But we only want to do this once though.
if impulse_applied == false:
print("Movement Impulse applied: ", h_speed.x)
calc_inertia.x += h_speed.x
impulse_applied = true
impulse_applied_dir = move_direction.x
print(impulse_applied_dir, " Movement Impulse applied: ", h_speed.x)
debug_speed_tracker = h_speed
# elif calc_inertia.x != 0.0:
# ##WIP: attempts to apply start speed only once

View File

@ -259,7 +259,8 @@ func _state_process_physics_land():
if !parent.is_on_floor():
#return fall_state
request_state_change.call_func('fall')
move_actor_as_desired()
#move_actor_as_desired()
apply_movement_to_parent(new_move_actor_as_desired( physics_delta , current_state ))
func _state_process_physics_hurt():
if current_state.state_timeout.time_left == 0:
@ -292,7 +293,8 @@ func _state_process_physics_fall():
#idle_state.modifier = landing_modifier
request_state_change.call_func('land')
move_actor_as_desired()
#move_actor_as_desired()
apply_movement_to_parent(new_move_actor_as_desired( physics_delta , current_state ))
func _state_process_physics_jump():
@ -438,7 +440,8 @@ func _state_process_physics_crouch_move():
elif _wants_crouch != true and desired_movement_vector.x != 0:
request_state_change.call_func('move')
move_actor_as_desired()
#move_actor_as_desired()
apply_movement_to_parent(new_move_actor_as_desired( physics_delta , current_state ))
#func _on_state_entered_idle():
# print("Movement State Idle State Entered!")

View File

@ -10,8 +10,14 @@ debug_state = false
timeout_seconds = 0.0
name = "idle"
horizontal_speed = 1.36422e-12
horizontal_acceleration = -60.0
horizontal_acceleration = 300.0
horizontal_speed_offset = 0.0
horizontal_speed_offset_acceleration = 0.0
jerk_factor = 0.0
vertical_speed = 0.0
vertical_acceleration = 0.0
vertical_speed_offset = 0.0
vertical_speed_offset_acceleration = 0.0
preserve_inertia = true
is_grounded = true
animation_sequence = [ "idle" ]

View File

@ -14,4 +14,10 @@ horizontal_acceleration = 1.36422e-12
horizontal_speed_offset = -140.0
horizontal_speed_offset_acceleration = -300.0
jerk_factor = 0.0
vertical_speed = 0.0
vertical_acceleration = 0.0
vertical_speed_offset = 0.0
vertical_speed_offset_acceleration = 0.0
preserve_inertia = false
is_grounded = true
animation_sequence = [ "roll" ]