Fall and jump follows similar impulse model for horizontal movement now.

This commit is contained in:
Dustin 2025-06-03 11:39:07 -07:00
parent e2c77b05e3
commit 544716502e
5 changed files with 62 additions and 53 deletions

View File

@ -362,17 +362,19 @@ func _state_process_physics_jump():
# #modifier.reference()
# #idle_state.modifier = landing_modifier
# request_state_change.call_func('idle')
if velocity_controller.velocity.y > 0:
request_state_change.call_func('fall')
return
desired_movement_vector.y = UP
#move_actor_as_desired()
apply_movement_to_parent(
velocity_controller.calculate_velocity(
physics_delta ,
apply_state_modifier(current_state.get_movement_parameters()),
desired_movement_vector )
)
## TODO: Our impulse model can't handle zero
if velocity_controller.velocity.y > - 2:
request_state_change.call_func('fall')
return
## Just slightly bump away from ledge we're bumping into
if (($"%JumpAdjustorBack".is_colliding() and !$"%JumpAdjustorFront".is_colliding()) or

View File

@ -123,7 +123,7 @@ __meta__ = {
[node name="Movement_StateReceiver" parent="." index="2"]
script = ExtResource( 6 )
debug_velocity_controller = false
debug_velocity_controller = true
[node name="Modifier_Receiver" parent="." index="3" instance=ExtResource( 35 )]
callable_state_machine = NodePath("../Movement_StateMachine")

View File

@ -9,7 +9,7 @@ script = ExtResource( 1 )
debug_state = false
timeout_seconds = 0.0
name = "fall"
speed_start = Vector2( 60, 1.36422e-12 )
speed_start = Vector2( 60, 1 )
speed_end = Vector2( 60, 1000 )
min_acceleration = Vector2( 0, 0 )
acceleration = Vector2( 1.36422e-12, 500 )

View File

@ -10,7 +10,7 @@ debug_state = false
timeout_seconds = 0.0
name = "jump"
speed_start = Vector2( 90, 200 )
speed_end = Vector2( 90, -8 )
speed_end = Vector2( 90, 1 )
min_acceleration = Vector2( 0, 0 )
acceleration = Vector2( 1.36422e-12, 360 )
max_acceleration = Vector2( 0, 0 )

View File

@ -21,10 +21,11 @@ enum IMPULSE_PLACEMENT {
## Could these be datatypes or a class? Sure
var _h_impulse_applied :bool = false
var _h_impulse_speed_tracking :Vector2
#var _h_impulse_speed_tracking :Vector2
var _h_impulse_placement_tracking :int = -1
var _v_impulse_applied :bool = false
var _v_impulse_speed_tracking :Vector2
#var _v_impulse_speed_tracking :Vector2
var _v_impulse_placement_tracking :int = -1
func calculate_velocity(_delta :float,
movement_parameters :MovementParameters,
@ -127,31 +128,27 @@ func calculate_velocity(_delta :float,
if debug:
print("Resetting H impulse (Impulse Placement Change)")
# if (h_range_placement == RANGE_PLACEMENT.WITHIN_RANGE and
# _h_impulse_speed_tracking != h_speed):
# if debug:
# print("Resetting H impulse (Within Range)")
# _h_impulse_applied = false
# elif(h_range_placement == RANGE_PLACEMENT.BEFORE_RANGE):
# if debug:
# print("Resetting H impulse (Before Range) ", _h_impulse_speed_tracking )
if (v_range_placement == RANGE_PLACEMENT.WITHIN_RANGE and
_v_impulse_applied == true and
_v_impulse_speed_tracking != v_speed):
if debug:
print("resetting V impulse")
_v_impulse_applied = false
if _v_impulse_applied == true:
if (v_range_placement == RANGE_PLACEMENT.WITHIN_RANGE):
_v_impulse_applied = false
if debug:
print("Resetting V impulse (Within Range)")
elif (calc_inertia.y < v_speed.x and _h_impulse_placement_tracking != IMPULSE_PLACEMENT.LEFT_SIDE or
calc_inertia.y >= v_speed.x and _h_impulse_placement_tracking != IMPULSE_PLACEMENT.RIGHT_SIDE):
_v_impulse_applied = false
if debug:
print("Resetting V impulse (Impulse Placement Change)")
## Separate impulse function
if _h_impulse_applied == false and is_zero_approx(h_speed.x) == false:# and _h_impulse_speed_tracking != h_speed:
#(range_placement :int, inertia :float, impulse_speed_range :Vector2)
#_h_impulse_speed_tracking = apply_impulse(h_range_placement, calc_inertia.x, h_speed )
var impulse_inertia = apply_impulse(h_range_placement, _h_impulse_speed_tracking , h_speed )
#var impulse_inertia = apply_impulse(h_range_placement, _h_impulse_speed_tracking , h_speed )
if h_range_placement == RANGE_PLACEMENT.PAST_RANGE and abs(h_speed.x) > abs(h_speed.y):
if debug:
print("Applying H impulse (Past Range): Imp: ", impulse_inertia, ", In:", calc_inertia.x)
_h_impulse_speed_tracking = h_speed
print("Applying H impulse (Past Range): Imp: ", ", In:", calc_inertia.x)
#_h_impulse_speed_tracking = h_speed
_h_impulse_applied = true
## This might not make sense
if (calc_inertia.x + h_speed.x) < h_speed.x:
@ -162,8 +159,8 @@ func calculate_velocity(_delta :float,
calc_inertia.x = h_speed.x
elif h_range_placement == RANGE_PLACEMENT.BEFORE_RANGE:
if debug:
print("Applying H impulse (Before Range): Imp: ", impulse_inertia, ", In:", calc_inertia.x)
_h_impulse_speed_tracking = h_speed
print("Applying H impulse (Before Range): Imp: ", ", In:", calc_inertia.x)
#_h_impulse_speed_tracking = h_speed
_h_impulse_applied = true
if calc_inertia.x < h_speed.x:
_h_impulse_placement_tracking = IMPULSE_PLACEMENT.LEFT_SIDE
@ -174,25 +171,42 @@ func calculate_velocity(_delta :float,
else:
##TODO: Maybe this should be something else
calc_inertia.x = 0
## F this, didn't work well
# if impulse_inertia != calc_inertia.x: ## We have an impulse to apply
# if debug:
# print("Applying H impulse: Imp: ", impulse_inertia, ", In:", calc_inertia.x)
# #var foo = 2+2
# _h_impulse_speed_tracking = h_speed
# _h_impulse_applied = true
# ## We want to add impulse in the direction of movement so we need to determine
# ## what that is.
# calc_inertia.x += impulse_inertia
if _v_impulse_applied == false:# and _v_impulse_speed_tracking != v_speed:
var impulse_inertia = apply_impulse(v_range_placement, _v_impulse_speed_tracking, v_speed)
if impulse_inertia != calc_inertia.y:
_v_impulse_speed_tracking = v_speed
if _v_impulse_applied == false and is_zero_approx(v_speed.x) == false:
#var impulse_inertia = apply_impulse(v_range_placement, _v_impulse_speed_tracking, v_speed)
if v_range_placement == RANGE_PLACEMENT.PAST_RANGE and abs(v_speed.x) > abs(v_speed.y):
if debug:
print("Applying V impulse (Past range)")
_v_impulse_applied = true
calc_inertia.y += impulse_inertia
if (calc_inertia.y + v_speed.x) < v_speed.x:
_v_impulse_placement_tracking = IMPULSE_PLACEMENT.LEFT_SIDE
else:
_v_impulse_placement_tracking = IMPULSE_PLACEMENT.RIGHT_SIDE
## We don't blow past the acceleration
calc_inertia.y = v_speed.x
elif v_range_placement == RANGE_PLACEMENT.BEFORE_RANGE:
if debug:
print("Applying V impulse (Before Range)")
_v_impulse_applied = true
if calc_inertia.y < v_speed.x:
_v_impulse_placement_tracking = IMPULSE_PLACEMENT.LEFT_SIDE
else:
_v_impulse_placement_tracking = IMPULSE_PLACEMENT.RIGHT_SIDE
if sign(v_speed.x) == sign(v_speed.y):
calc_inertia.y += v_speed.x
else:
##TODO : this should probably be smarter
calc_inertia.y = 0
# elif v_range_placement == RANGE_PLACEMENT.WITHIN_RANGE and _v_impulse_placement_tracking != range_placement:
# if debug:
# print("Apply V impulse (within range)")
# _v_impulse_applied = true
# if calc_inertia.y < v_speed.x:
# _v_impulse_placement_tracking = IMPULSE_PLACEMENT.LEFT_SIDE
# else:
# _v_impulse_placement_tracking = IMPULSE_PLACEMENT.RIGHT_SIDE
# calc_inertia.y = v_speed.x
if debug and movement_parameters.debug_name == 'roll':
var foo = 2+2
## We are always moving from h_speed.x towards y at a given rate
@ -227,13 +241,6 @@ func calculate_velocity(_delta :float,
# if is_zero_approx(_movement_direction.y) == false:
# calc_inertia.y = v_speed.x
calc_inertia.y = v_speed.x
## Track or last speed for in range impulses
# _h_impulse_speed_tracking = h_speed
# _v_impulse_speed_tracking = v_speed
#calc_velocity.y = calc_inertia.y
#calc_velocity.x = calc_inertia.x
if debug:
UiManager.debug_text = ( #"H_Speed x Dir: " + str(h_speed) + str('duh') +