Movement much better. More testing needed.
This commit is contained in:
parent
dc6802cbce
commit
7d210d7900
|
|
@ -137,14 +137,12 @@ func _on_state_change(old_state_name:String, new_state :State):
|
|||
#current_state = new_state
|
||||
|
||||
## Side effects for these variables
|
||||
# velocity
|
||||
# momentum
|
||||
# acceleration
|
||||
# velocity - doesn't change but uses it to set base calculations
|
||||
# accepts the state to determine movement, the deltatime, and an optional direction
|
||||
# Update: Actually should just return movement in PPS
|
||||
##
|
||||
var calc_inertia = velocity.abs()
|
||||
var calc_inertial_dir :Vector2
|
||||
#var calc_inertia = velocity.abs()
|
||||
#var calc_inertial_dir :Vector2
|
||||
var debug_speed_tracker :Vector2
|
||||
func new_move_actor_as_desired(_delta :float,
|
||||
_state :StateAnimatedActor,
|
||||
|
|
@ -161,8 +159,9 @@ func new_move_actor_as_desired(_delta :float,
|
|||
var calc_velocity = Vector2.ZERO
|
||||
var calc_acceleration = Vector2.ZERO
|
||||
#var calc_inertia = Vector2.ZERO
|
||||
#var calc_inertia = inertia
|
||||
var friction :Vector2 = Vector2.ZERO
|
||||
var calc_inertia = velocity.abs()
|
||||
var calc_inertial_dir = Vector2(sign(velocity.x),sign(velocity.y))
|
||||
var calc_friction :Vector2 = Vector2.ZERO
|
||||
|
||||
## Inertia only applies if there is a difference between the
|
||||
# base move speed and a derived move speed. This makes it so all you
|
||||
|
|
@ -191,11 +190,16 @@ func new_move_actor_as_desired(_delta :float,
|
|||
## if we have a difference of speed
|
||||
if h_speed.x != h_speed.y:
|
||||
debug_speed_tracker = h_speed
|
||||
## Aceleration needs to be the sign of the direction we're moving in
|
||||
## Clamp inertia to in between speed.
|
||||
# Problem is that we can suddenly gain or lose inertia.
|
||||
##
|
||||
calc_inertia.x = clamp( calc_inertia.x + (calc_acceleration.x * _delta),
|
||||
h_speed.x , h_speed.y)
|
||||
|
||||
## Disable this for now hopefully inertial acceleration flip removes this
|
||||
## Update: it mostly did. Going to keep this here for a while though.
|
||||
# The above problem may need a few different scenarios when there is already
|
||||
# applied inertia.
|
||||
# if calc_inertia.x == 0.0:
|
||||
# #calc_inertia.x = lerp( h_speed.x , h_speed.y, calc_acceleration.x * _delta)
|
||||
# calc_inertia.x = clamp( calc_inertia.x + (calc_acceleration.x * _delta),
|
||||
|
|
@ -204,7 +208,7 @@ func new_move_actor_as_desired(_delta :float,
|
|||
# #calc_inertia.x = lerp( calc_inertia.x, h_speed.y, calc_acceleration.x * _delta)
|
||||
# calc_inertia.x = clamp( calc_inertia.x + ( calc_acceleration.x * _delta),
|
||||
# calc_inertia.x, h_speed.y)
|
||||
elif calc_inertia.x != 0.0: ## We still have inertia
|
||||
elif calc_inertia.x != 0.0: ## We still have inertia but no difference in movement
|
||||
if calc_acceleration.x != 0.0: # We are applying acceleration
|
||||
if calc_inertia.x > h_speed.x:
|
||||
calc_inertia.x = clamp( calc_inertia.x + ( calc_acceleration.x * _delta),
|
||||
|
|
@ -216,26 +220,27 @@ func new_move_actor_as_desired(_delta :float,
|
|||
## Neutralize the inertia? but how?
|
||||
## Recalc the acceleration with inertia
|
||||
#var friction :Vector2
|
||||
friction.x = resolve_h_acceleration(movement_params,Vector2(calc_inertia.x, h_speed.x), move_direction.x)
|
||||
if friction.x != 0.0: ## No dapening acceleration applies
|
||||
calc_friction.x = resolve_h_acceleration(movement_params,Vector2(calc_inertia.x, h_speed.x), move_direction.x)
|
||||
if calc_friction.x != 0.0: ## No dapening acceleration applies
|
||||
if calc_inertia.x > h_speed.x: ## Inertia is higher than the base speed (slow it down)
|
||||
calc_inertia.x = clamp( calc_inertia.x + ( friction.x * _delta),
|
||||
calc_inertia.x = clamp( calc_inertia.x + ( calc_friction.x * _delta),
|
||||
h_speed.x, calc_inertia.x)
|
||||
else: ## Inertia lower than base speed (we need to catch up)
|
||||
calc_inertia.x = clamp( calc_inertia.x + ( friction.x * _delta),
|
||||
calc_inertia.x = clamp( calc_inertia.x + ( calc_friction.x * _delta),
|
||||
calc_inertia.x, h_speed.x)
|
||||
else:
|
||||
## no residual acceleration (friction) applies, kill the momentum
|
||||
calc_inertia.x = 0.0
|
||||
calc_inertial_dir.x = 0.0
|
||||
|
||||
if (h_speed != debug_speed_tracker):
|
||||
print("Inertia SpeedShift: ", debug_speed_tracker, h_speed, (0.0 == -0.0))
|
||||
debug_speed_tracker = h_speed
|
||||
# if (h_speed != debug_speed_tracker):
|
||||
# print("Inertia SpeedShift: ", debug_speed_tracker, h_speed, (0.0 == -0.0))
|
||||
# debug_speed_tracker = h_speed
|
||||
|
||||
else:
|
||||
## inertia is just base speed
|
||||
calc_inertia.x = h_speed.x
|
||||
acceleration = Vector2.ZERO
|
||||
calc_inertial_dir.x = 0.0
|
||||
|
||||
|
||||
## Another idea, just return the calculated velocity in PPS
|
||||
|
|
@ -255,14 +260,15 @@ func new_move_actor_as_desired(_delta :float,
|
|||
else:
|
||||
calc_velocity.x = calc_inertia.x * move_direction.x
|
||||
|
||||
calc_inertial_dir = Vector2(sign(calc_velocity.x),sign(calc_velocity.y))
|
||||
## 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') +
|
||||
"H_Speed: {0}, {1}".format({"0":"%5.2f" % h_speed.x, "1":"%5.2f" % h_speed.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}) +
|
||||
"\nVelocity_Real: {0}, {1}".format({"0":"%5.2f" % velocity.x, "1":"%5.2f" % velocity.y}) +
|
||||
"\nFriction: {0}, {1}".format({"0":"%5.2f" % friction.x, "1":"%5.2f" % 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}) +
|
||||
|
||||
#"\nLength: " + str(velocity.length()) +
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user