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,12 +195,12 @@ func new_move_actor_as_desired(_delta :float,
else: else:
move_direction = resolve_move_direction(calc_inertial_dir, desired_movement_vector) move_direction = resolve_move_direction(calc_inertial_dir, desired_movement_vector)
##TODO: the impulse logic just doesn't work still ##WIP: the impulse logic just doesn't work still, below is another attempt
if sign(calc_velocity.x) != move_direction.x and sign(calc_velocity.x) != impulse_applied_dir: # if impulse_applied_dir != move_direction.x and sign(calc_velocity.x) != impulse_applied_dir:
print("resetting impulse") # print("resetting impulse")
impulse_applied = false # impulse_applied = false
impulse_applied_dir = sign(move_direction.x) # impulse_applied_dir = sign(move_direction.x)
var modifier_indicator := '' var modifier_indicator := ''
var movement_parameters :MovementParameters = _state.get_movement_parameters() var movement_parameters :MovementParameters = _state.get_movement_parameters()
@ -223,7 +223,14 @@ func new_move_actor_as_desired(_delta :float,
var h_speed = resolve_h_speed(movement_parameters) var h_speed = resolve_h_speed(movement_parameters)
## Speed will now be expected to move in the direction of travel ## Speed will now be expected to move in the direction of travel
h_speed *= move_direction.x 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 ## 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 # Any non zero speed that goes opposite to our inertial direction
# should only be allowed once. # 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: 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. ## ? But we only want to do this once though.
if impulse_applied == false: if impulse_applied == false:
print("Movement Impulse applied: ", h_speed.x)
calc_inertia.x += h_speed.x calc_inertia.x += h_speed.x
impulse_applied = true impulse_applied = true
impulse_applied_dir = move_direction.x impulse_applied_dir = move_direction.x
print(impulse_applied_dir, " Movement Impulse applied: ", h_speed.x)
debug_speed_tracker = h_speed debug_speed_tracker = h_speed
# elif calc_inertia.x != 0.0: # elif calc_inertia.x != 0.0:
# ##WIP: attempts to apply start speed only once # ##WIP: attempts to apply start speed only once

View File

@ -259,7 +259,8 @@ func _state_process_physics_land():
if !parent.is_on_floor(): if !parent.is_on_floor():
#return fall_state #return fall_state
request_state_change.call_func('fall') 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(): func _state_process_physics_hurt():
if current_state.state_timeout.time_left == 0: if current_state.state_timeout.time_left == 0:
@ -292,7 +293,8 @@ func _state_process_physics_fall():
#idle_state.modifier = landing_modifier #idle_state.modifier = landing_modifier
request_state_change.call_func('land') 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(): 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: elif _wants_crouch != true and desired_movement_vector.x != 0:
request_state_change.call_func('move') 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(): #func _on_state_entered_idle():
# print("Movement State Idle State Entered!") # print("Movement State Idle State Entered!")

View File

@ -10,8 +10,14 @@ debug_state = false
timeout_seconds = 0.0 timeout_seconds = 0.0
name = "idle" name = "idle"
horizontal_speed = 1.36422e-12 horizontal_speed = 1.36422e-12
horizontal_acceleration = -60.0 horizontal_acceleration = 300.0
horizontal_speed_offset = 0.0 horizontal_speed_offset = 0.0
horizontal_speed_offset_acceleration = 0.0 horizontal_speed_offset_acceleration = 0.0
jerk_factor = 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" ] animation_sequence = [ "idle" ]

View File

@ -14,4 +14,10 @@ horizontal_acceleration = 1.36422e-12
horizontal_speed_offset = -140.0 horizontal_speed_offset = -140.0
horizontal_speed_offset_acceleration = -300.0 horizontal_speed_offset_acceleration = -300.0
jerk_factor = 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 = false
is_grounded = true
animation_sequence = [ "roll" ] animation_sequence = [ "roll" ]