Vertical application of jump on new range based model.

This commit is contained in:
Dustin 2025-05-08 21:14:10 -07:00
parent 07f992d729
commit 05580ee50d
2 changed files with 71 additions and 38 deletions

View File

@ -161,6 +161,12 @@ enum RANGE_PLACEMENT {
var debug_speed_tracker :Vector2 var debug_speed_tracker :Vector2
var impulse_applied_dir :float = 0.0 var impulse_applied_dir :float = 0.0
var impulse_applied :bool = false var impulse_applied :bool = false
## Could these be datatypes or a class? Sure
var _h_impulse_applied :bool = false
var _h_impulse_speed_tracking :Vector2
var _v_impulse_applied :bool = false
var _v_impulse_speed_tracking :Vector2
func new_move_actor_as_desired(_delta :float, func new_move_actor_as_desired(_delta :float,
_state :StateAnimatedActor, _state :StateAnimatedActor,
_movement_override_normal := Vector2(0,0), _movement_override_normal := Vector2(0,0),
@ -238,10 +244,13 @@ func new_move_actor_as_desired(_delta :float,
## Reset the impulse when back in range ## Reset the impulse when back in range
# may also want to reset when hspeed is static # may also want to reset when hspeed is static
if (h_range_placement == RANGE_PLACEMENT.WITHIN_RANGE and if (h_range_placement == RANGE_PLACEMENT.WITHIN_RANGE and
impulse_applied == true ): _h_impulse_applied == true ):
print("resetting impulse") print("resetting H impulse")
impulse_applied = false _h_impulse_applied = false
if (v_range_placement == RANGE_PLACEMENT.WITHIN_RANGE and
_v_impulse_applied == true ):
print("resetting V impulse")
_v_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.
@ -273,18 +282,19 @@ func new_move_actor_as_desired(_delta :float,
match h_range_placement: match h_range_placement:
RANGE_PLACEMENT.BEFORE_RANGE: RANGE_PLACEMENT.BEFORE_RANGE:
## Also apply impulse here ## Also apply impulse here
if impulse_applied == false: if _h_impulse_applied == false:
calc_inertia.x += h_speed.x calc_inertia.x += h_speed.x
impulse_applied = true _h_impulse_applied = true
impulse_applied_dir = move_direction.x #impulse_applied_dir = move_direction.x
calc_inertia.x = clamp(calc_inertia.x + direction_accel, calc_inertia.x = clamp(calc_inertia.x + direction_accel,
min(calc_inertia.x, h_speed.y), min(calc_inertia.x, h_speed.y),
max(calc_inertia.x, h_speed.y)) max(calc_inertia.x, h_speed.y))
RANGE_PLACEMENT.WITHIN_RANGE: RANGE_PLACEMENT.WITHIN_RANGE:
if impulse_applied == false and calc_inertia.x == 0.0: ## If we're within the range but our speed has just changed
calc_inertia.x += h_speed.x if _h_impulse_applied == false and _h_impulse_speed_tracking != h_speed:
impulse_applied = true ## Set inertia to starting speed, we're already in range
impulse_applied_dir = move_direction.x calc_inertia.x = h_speed.x
_h_impulse_applied = true
calc_inertia.x = clamp(calc_inertia.x + direction_accel, calc_inertia.x = clamp(calc_inertia.x + direction_accel,
min(h_speed.x, h_speed.y), min(h_speed.x, h_speed.y),
max(h_speed.x, h_speed.y)) max(h_speed.x, h_speed.y))
@ -317,38 +327,61 @@ func new_move_actor_as_desired(_delta :float,
## Another idea, just return the calculated velocity in PPS ## Another idea, just return the calculated velocity in PPS
## For now, y component of velocity is just gravity ## For now, y component of velocity is just gravity
if v_speed.x != v_speed.y: ## For now gravity is just the default acceleration if v_speed.x != v_speed.y: ## For now gravity is just the default acceleration
if (v_speed.x != 0 and v_speed.y != 0) and sign(v_speed.y) != sign(v_speed.x): var direction_accel :float = movement_parameters.gravity * _delta #* move_direction.x
if v_speed.x < v_speed.y: if v_speed.x > v_speed.y:
v_speed.x = clamp(v_speed.x, 0.0, v_speed.y) direction_accel *= -1
else: match v_range_placement:
v_speed.y = clamp(v_speed.y, 0.0, v_speed.x) RANGE_PLACEMENT.BEFORE_RANGE:
#print (is_out_of_range(calc_inertia.y, v_speed.x - sign(v_speed.x), v_speed.y - sign(v_speed.y))) ## Also apply impulse here
if is_out_of_range(calc_inertia.y, v_speed.x , v_speed.y): if _v_impulse_applied == false:
## ? But we only want to do this once though. calc_inertia.y += v_speed.x
calc_inertia.y += v_speed.x _v_impulse_applied = true
## Apply acceleration #impulse_applied_dir = move_direction.x
calc_inertia.y = move_toward(calc_inertia.y, v_speed.y, movement_parameters.gravity * _delta) calc_inertia.y = clamp(calc_inertia.y + direction_accel,
min(calc_inertia.x, v_speed.y),
max(calc_inertia.x, v_speed.y))
RANGE_PLACEMENT.WITHIN_RANGE:
## If we're within the range but our speed has just changed
if _v_impulse_applied == false and _v_impulse_speed_tracking != v_speed:
## Set inertia to starting speed, we're already in range
calc_inertia.y = v_speed.x
_v_impulse_applied = true
calc_inertia.y = clamp(calc_inertia.y + direction_accel,
min(v_speed.x, v_speed.y),
max(v_speed.x, v_speed.y))
RANGE_PLACEMENT.PAST_RANGE:
calc_inertia.y = clamp(calc_inertia.y - direction_accel, # Friction
min(calc_inertia.y, v_speed.y),
max(calc_inertia.y, v_speed.y))
# if _state.name == 'jump':
# var _foo = clamp(calc_inertia.y + direction_accel,
# min(v_speed.x, v_speed.y),
# max(v_speed.x, v_speed.y))
# print ("foo: ", _foo)
# if (v_speed.x != 0 and v_speed.y != 0) and sign(v_speed.y) != sign(v_speed.x):
# if v_speed.x < v_speed.y:
# v_speed.x = clamp(v_speed.x, 0.0, v_speed.y)
# else:
# v_speed.y = clamp(v_speed.y, 0.0, v_speed.x)
# #print (is_out_of_range(calc_inertia.y, v_speed.x - sign(v_speed.x), v_speed.y - sign(v_speed.y)))
# if is_out_of_range(calc_inertia.y, v_speed.x , v_speed.y):
# ## ? But we only want to do this once though.
# calc_inertia.y += v_speed.x
# ## Apply acceleration
# calc_inertia.y = move_toward(calc_inertia.y, v_speed.y, movement_parameters.gravity * _delta)
else: else:
## The previous vertical movement methods ## The previous vertical movement methods
calc_inertia.y += movement_parameters.gravity * _delta calc_inertia.y += movement_parameters.gravity * _delta
## 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.y = calc_inertia.y
## calc x component of felicty
## Can't do it this way when we have initia
#calc_velocity.x = calc_inertia.x * move_direction.x
## Control, direction can only be controlled when overcome inertia direction.
# 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_velocity.x = calc_inertia.x calc_velocity.x = calc_inertia.x
## Attempting to move this to the top
#calc_inertial_dir = Vector2(sign(calc_velocity.x),sign(calc_velocity.y))
UiManager.debug_text = ( #"H_Speed x Dir: " + str(h_speed) + str('duh') + UiManager.debug_text = ( #"H_Speed x Dir: " + str(h_speed) + str('duh') +
modifier_indicator + "H_Speed Fm:{0} To:{1}".format({"0":"%5.2f" % h_speed.x, "1":"%5.2f" % h_speed.y}) + modifier_indicator + "H_Speed Fm:{0} To:{1}".format({"0":"%5.2f" % h_speed.x, "1":"%5.2f" % h_speed.y}) +
"\nV_Speed Fm:{0} To:{1}".format({"0":"%5.2f" % v_speed.x, "1":"%5.2f" % v_speed.y}) + "\nV_Speed Fm:{0} To:{1}".format({"0":"%5.2f" % v_speed.x, "1":"%5.2f" % v_speed.y}) +

View File

@ -16,7 +16,7 @@ horizontal_speed_offset_acceleration = 0.0
jerk_factor = 1.0 jerk_factor = 1.0
vertical_speed = 200.0 vertical_speed = 200.0
vertical_acceleration = 0.0 vertical_acceleration = 0.0
vertical_speed_offset = -200.0 vertical_speed_offset = -208.0
vertical_speed_offset_acceleration = 0.0 vertical_speed_offset_acceleration = 0.0
preserve_inertia = true preserve_inertia = true
is_grounded = false is_grounded = false