Impulse maybe working

This commit is contained in:
Dustin 2025-05-26 12:05:41 -07:00
parent e7f08fd351
commit 4a95ec08f4
2 changed files with 43 additions and 29 deletions

View File

@ -12,7 +12,7 @@ name = "move"
speed_start = Vector2( 10, 1.36422e-12 )
speed_end = Vector2( 90, 1000 )
min_acceleration = Vector2( 0, 0 )
acceleration = Vector2( 1000, 280 )
acceleration = Vector2( 20, 280 )
max_acceleration = Vector2( 0, 0 )
jerk_factor = Vector2( 1, 1 )
horizontal_speed = 10.0

View File

@ -109,35 +109,41 @@ func calculate_velocity(_delta :float,
## Reset the impulse when back in range
# may also want to reset when hspeed is static
if (h_range_placement == RANGE_PLACEMENT.WITHIN_RANGE and
_h_impulse_applied == true ):
_h_impulse_applied == true and
_h_impulse_speed_tracking != h_speed):
if debug:
print("resetting H impulse")
_h_impulse_applied = false
if (v_range_placement == RANGE_PLACEMENT.WITHIN_RANGE and
_v_impulse_applied == true ):
_v_impulse_applied == true and
_v_impulse_speed_tracking != v_speed):
if debug:
print("resetting V impulse")
_v_impulse_applied = false
## Separate impulse function
if _h_impulse_applied == false and _h_impulse_speed_tracking != h_speed:
if _h_impulse_applied == 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, calc_inertia.x, h_speed )
if impulse_inertia != calc_inertia.x:
var impulse_inertia = apply_impulse(h_range_placement, _h_impulse_speed_tracking , h_speed )
if impulse_inertia != calc_inertia.x: ## We have an impulse to apply
if debug:
print("Applying H impulse")
#var foo = 2+2
#_h_impulse_speed_tracking = h_speed
_h_impulse_speed_tracking = h_speed
_h_impulse_applied = true
calc_inertia.x = impulse_inertia
## 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,calc_inertia.y, v_speed)
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
_v_impulse_speed_tracking = v_speed
_v_impulse_applied = true
calc_inertia.y = impulse_inertia
calc_inertia.y += impulse_inertia
if debug and movement_parameters.debug_name == 'fall':
if debug and movement_parameters.debug_name == 'jump':
var foo = 2+2
## We are always moving from h_speed.x towards y at a given rate
## if we have a difference of speed and an acceleration
@ -156,11 +162,11 @@ func calculate_velocity(_delta :float,
)
## Track or last speed for in range impulses
_h_impulse_speed_tracking = h_speed
_v_impulse_speed_tracking = v_speed
# _h_impulse_speed_tracking = h_speed
# _v_impulse_speed_tracking = v_speed
calc_velocity.y = calc_inertia.y
calc_velocity.x = calc_inertia.x
#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') +
@ -177,7 +183,7 @@ func calculate_velocity(_delta :float,
"\nMoveDir: {0}, {1}".format({"0":"%4.1f" % move_direction.x, "1":"%4.1f" % move_direction.y})
)
return calc_velocity
return calc_inertia
func is_out_of_range(value: float, a: float, b: float) -> bool:
var lower = min(a, b)
@ -193,17 +199,21 @@ func placement_to_speed_range(speed: float, speed_range: Vector2) -> int:
#var range_start :float = min(speed_range.x, speed_range.y)
#var range_end :float = max(speed_range.x, speed_range.y)
##TODO: Do I also need an equivalent
if is_equal_approx(speed, speed_range.x) or is_equal_approx(speed, speed_range.y):
return RANGE_PLACEMENT.WITHIN_RANGE
## We can be at the base range to ensure impulse can happen
## Direction <-- that way
if speed_range.x > speed_range.y:
if speed < speed_range.x and speed >= speed_range.y:
if speed < speed_range.x and speed > speed_range.y:
return RANGE_PLACEMENT.WITHIN_RANGE
elif speed < speed_range.y:
return RANGE_PLACEMENT.PAST_RANGE
else:
return RANGE_PLACEMENT.BEFORE_RANGE
else: ## Direction --> that way
if speed > speed_range.x and speed <= speed_range.y:
if speed > speed_range.x and speed < speed_range.y:
return RANGE_PLACEMENT.WITHIN_RANGE
elif speed > speed_range.y:
return RANGE_PLACEMENT.PAST_RANGE
@ -228,21 +238,25 @@ func resolve_move_direction(_momentum :Vector2,
return Vector2(horizontal_movement_direction, vertical_movement_direction)
func apply_impulse(range_placement :int, inertia :float, impulse_speed_range :Vector2) -> float:
func apply_impulse(range_placement :int, tracking_range :Vector2, impulse_speed_range :Vector2) -> float:
match range_placement:
RANGE_PLACEMENT.BEFORE_RANGE:
inertia += impulse_speed_range.x
return inertia
# inertia += impulse_speed_range.x
# return inertia
return impulse_speed_range.x
RANGE_PLACEMENT.WITHIN_RANGE:
#if impulse_status == false: # and _h_impulse_speed_tracking != impulse_speed:
var track_stuff = placement_to_speed_range(tracking_range.x, impulse_speed_range)
if tracking_range != impulse_speed_range:
## Set inertia to starting speed, we're already in range
inertia = impulse_speed_range.x
return inertia
return impulse_speed_range.x
RANGE_PLACEMENT.PAST_RANGE:
## If this is a reduced speed move otherwise we usually want to slow down
## because we're past the range
if abs(impulse_speed_range.x) > abs(impulse_speed_range.y):
inertia = impulse_speed_range.x
return inertia
return inertia
# inertia = impulse_speed_range.x
# return inertia
return impulse_speed_range.x
return 0.0
func resolve_inertia(range_placement :int,
inertia :float ,