Compare commits
No commits in common. "07f992d729beb5cb2ab1c6e8f9e9c174be79cc5e" and "c6de01ba1ab84bb467f2c9d88073c743e22cbfd3" have entirely different histories.
07f992d729
...
c6de01ba1a
|
|
@ -145,11 +145,6 @@ func _on_modifiers_updated(_modifier_type :int, _modifier_action :int, _merged_m
|
||||||
modifier = _merged_modifier
|
modifier = _merged_modifier
|
||||||
|
|
||||||
|
|
||||||
enum RANGE_PLACEMENT {
|
|
||||||
BEFORE_RANGE = -1,
|
|
||||||
WITHIN_RANGE = 0,
|
|
||||||
PAST_RANGE = 1
|
|
||||||
}
|
|
||||||
|
|
||||||
## Side effects for these variables
|
## Side effects for these variables
|
||||||
# velocity - doesn't change but uses it to set base calculations
|
# velocity - doesn't change but uses it to set base calculations
|
||||||
|
|
@ -231,13 +226,9 @@ func new_move_actor_as_desired(_delta :float,
|
||||||
h_speed *= move_direction.x
|
h_speed *= move_direction.x
|
||||||
v_speed *= move_direction.y
|
v_speed *= move_direction.y
|
||||||
|
|
||||||
## Now determine placement of current velocity to speed range
|
|
||||||
var h_range_placement = placement_to_speed_range(calc_velocity.x, h_speed)
|
|
||||||
var v_range_placement = placement_to_speed_range(calc_velocity.y, v_speed)
|
|
||||||
|
|
||||||
## 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 (is_out_of_range(calc_inertia.x, h_speed.x, h_speed.y) == false and
|
||||||
impulse_applied == true ):
|
impulse_applied == true ):
|
||||||
print("resetting impulse")
|
print("resetting impulse")
|
||||||
impulse_applied = false
|
impulse_applied = false
|
||||||
|
|
@ -262,36 +253,56 @@ func new_move_actor_as_desired(_delta :float,
|
||||||
# #calc_friction.x = calc_acceleration.x * -1
|
# #calc_friction.x = calc_acceleration.x * -1
|
||||||
# calc_friction.x = abs(calc_acceleration.x)
|
# calc_friction.x = abs(calc_acceleration.x)
|
||||||
# calc_acceleration.x = 0.0
|
# calc_acceleration.x = 0.0
|
||||||
#h_speed != debug_speed_tracker
|
|
||||||
|
|
||||||
## We are always moving from h_speed.x towards y at a given rate
|
## We are always moving from h_speed.x towards y at a given rate
|
||||||
## if we have a difference of speed and an acceleration
|
## if we have a difference of speed and an acceleration
|
||||||
##TODO: The Min Max could be augmented to just be h_speed.x and prevent the sliding.
|
|
||||||
if h_speed.x != h_speed.y and calc_acceleration.x != 0.0:
|
if h_speed.x != h_speed.y and calc_acceleration.x != 0.0:
|
||||||
var direction_accel :float = calc_acceleration.x * _delta #* move_direction.x
|
|
||||||
if h_speed.x > h_speed.y:
|
## Start speed really shouldn't be less than zero (modifiers can do this)
|
||||||
direction_accel *= -1
|
## If we have mismatched signs we'll get really bad behavior
|
||||||
match h_range_placement:
|
if (h_speed.x != 0 and h_speed.y != 0 ) and sign(h_speed.y) != sign(h_speed.x):
|
||||||
RANGE_PLACEMENT.BEFORE_RANGE:
|
if h_speed.x < h_speed.y:
|
||||||
## Also apply impulse here
|
h_speed.x = clamp(h_speed.x, 0.0, h_speed.y)
|
||||||
|
else:
|
||||||
|
h_speed.y = clamp(h_speed.y, 0.0, h_speed.x)
|
||||||
|
|
||||||
|
##TODO: Find a better way to apply impulse on target velocity changes.
|
||||||
|
## Determine whether we should apply impulse
|
||||||
|
## If there is currently no inertia apply the base h_speed
|
||||||
|
## If the direction of our inertia is different to our intended speed direction
|
||||||
|
# and the inertia is not already in range of the movement speed, apply impulse.
|
||||||
|
# range part is working but we need to also apply it when we have zero
|
||||||
|
# velocity, hopefully we're at full stop at this point
|
||||||
|
##
|
||||||
|
if sign(calc_inertia.x) != sign(h_speed.x):
|
||||||
|
## Only if inertia is not already in range.
|
||||||
|
# if calc_inertia.x <= h_speed.x or calc_inertia.x >= h_speed.y:
|
||||||
|
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:
|
if impulse_applied == false:
|
||||||
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
|
||||||
calc_inertia.x = clamp(calc_inertia.x + direction_accel,
|
print(impulse_applied_dir, " Movement Impulse applied: ", h_speed.x)
|
||||||
min(calc_inertia.x, h_speed.y),
|
debug_speed_tracker = h_speed
|
||||||
max(calc_inertia.x, h_speed.y))
|
# elif calc_inertia.x != 0.0:
|
||||||
RANGE_PLACEMENT.WITHIN_RANGE:
|
# ##WIP: attempts to apply start speed only once
|
||||||
if impulse_applied == false and calc_inertia.x == 0.0:
|
# if h_speed.x < h_speed.y:
|
||||||
calc_inertia.x += h_speed.x
|
# if calc_inertia.x < h_speed.x and sign(move_direction.x) == calc_inertial_dir.x:
|
||||||
impulse_applied = true
|
# calc_inertia.x = h_speed.x
|
||||||
impulse_applied_dir = move_direction.x
|
# elif h_speed.x > h_speed.y:
|
||||||
calc_inertia.x = clamp(calc_inertia.x + direction_accel,
|
# if calc_inertia.x > h_speed.x and sign(move_direction.x) == calc_inertial_dir.x:
|
||||||
min(h_speed.x, h_speed.y),
|
# calc_inertia.x = h_speed.x
|
||||||
max(h_speed.x, h_speed.y))
|
|
||||||
RANGE_PLACEMENT.PAST_RANGE:
|
if modifier and modifier.is_active:
|
||||||
calc_inertia.x = clamp(calc_inertia.x - direction_accel, # Friction
|
var foo = 2+2 # breakpoint check
|
||||||
min(calc_inertia.x, h_speed.y),
|
|
||||||
max(calc_inertia.x, h_speed.y))
|
## Apply acceleration
|
||||||
|
calc_inertia.x = move_toward(calc_inertia.x, h_speed.y, calc_acceleration.x * _delta)
|
||||||
|
## Apply friction
|
||||||
|
#calc_inertia.x = move_toward(calc_inertia.x, 0, abs(calc_friction.x * _delta))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
elif calc_inertia.x != 0.0 and calc_acceleration.x != 0.0: ## We still have inertia but no difference in movement
|
elif calc_inertia.x != 0.0 and calc_acceleration.x != 0.0: ## We still have inertia but no difference in movement
|
||||||
|
|
@ -352,13 +363,12 @@ func new_move_actor_as_desired(_delta :float,
|
||||||
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}) +
|
||||||
"\nSpeedRange : {0}, {1}".format({"0":"%5.2f" % h_range_placement, "1":"%5.2f" % v_range_placement}) +
|
|
||||||
"\nVelocity_Calc: {0}, {1}".format({"0":"%5.2f" % calc_velocity.x, "1":"%5.2f" % calc_velocity.y}) +
|
"\nVelocity_Calc: {0}, {1}".format({"0":"%5.2f" % calc_velocity.x, "1":"%5.2f" % calc_velocity.y}) +
|
||||||
"\nInertia_Calc: {0}, {1}".format({"0":"%5.2f" % calc_inertia.x, "1":"%5.2f" % calc_inertia.y}) +
|
"\nInertia_Calc: {0}, {1}".format({"0":"%5.2f" % calc_inertia.x, "1":"%5.2f" % calc_inertia.y}) +
|
||||||
"\nVelocity_Real: {0}, {1}".format({"0":"%5.2f" % velocity.x, "1":"%5.2f" % velocity.y}) +
|
"\nVelocity_Real: {0}, {1}".format({"0":"%5.2f" % velocity.x, "1":"%5.2f" % velocity.y}) +
|
||||||
#"\nFriction: {0}, {1}".format({"0":"%5.2f" % calc_friction.x, "1":"%5.2f" % calc_friction.y}) +
|
#"\nFriction: {0}, {1}".format({"0":"%5.2f" % calc_friction.x, "1":"%5.2f" % calc_friction.y}) +
|
||||||
"\nAccelCalc : {0}, {1}".format({"0":"%5.2f" % calc_acceleration.x, "1":"%5.2f" % calc_acceleration.y}) +
|
"\nAccelCalc : {0}, {1}".format({"0":"%5.2f" % calc_acceleration.x, "1":"%5.2f" % calc_acceleration.y}) +
|
||||||
# h_range_placement
|
|
||||||
#"\nLength: " + str(velocity.length()) +
|
#"\nLength: " + str(velocity.length()) +
|
||||||
"\nMoveDir: {0}, {1}".format({"0":"%4.1f" % move_direction.x, "1":"%4.1f" % move_direction.y})
|
"\nMoveDir: {0}, {1}".format({"0":"%4.1f" % move_direction.x, "1":"%4.1f" % move_direction.y})
|
||||||
)
|
)
|
||||||
|
|
@ -370,33 +380,6 @@ func is_out_of_range(value: float, a: float, b: float) -> bool:
|
||||||
var upper = max(a, b)
|
var upper = max(a, b)
|
||||||
return value <= lower or value >= upper
|
return value <= lower or value >= upper
|
||||||
|
|
||||||
## Determine the trend of direction and where our current speed is
|
|
||||||
# in relation to it. This should help determine the direction of
|
|
||||||
# acceleration and whether we speed up or slow down.
|
|
||||||
##
|
|
||||||
func placement_to_speed_range(speed: float, speed_range: Vector2) -> int:
|
|
||||||
## Actually we don't care about mix or min
|
|
||||||
#var range_start :float = min(speed_range.x, speed_range.y)
|
|
||||||
#var range_end :float = max(speed_range.x, speed_range.y)
|
|
||||||
|
|
||||||
## 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:
|
|
||||||
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:
|
|
||||||
return RANGE_PLACEMENT.WITHIN_RANGE
|
|
||||||
elif speed > speed_range.y:
|
|
||||||
return RANGE_PLACEMENT.PAST_RANGE
|
|
||||||
else:
|
|
||||||
return RANGE_PLACEMENT.BEFORE_RANGE
|
|
||||||
return 0
|
|
||||||
|
|
||||||
## Passed in acceleration, vel, etc is applied to whatever
|
## Passed in acceleration, vel, etc is applied to whatever
|
||||||
## the parent is. If Kinematic then move_and_slide, otherwise manually adjusted
|
## the parent is. If Kinematic then move_and_slide, otherwise manually adjusted
|
||||||
func apply_movement_to_parent( _velocity :Vector2) -> void:
|
func apply_movement_to_parent( _velocity :Vector2) -> void:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user