|
|
|
|
@ -146,7 +146,8 @@ func _on_state_change(old_state_name:String, new_state :State):
|
|
|
|
|
var debug_speed_tracker :Vector2
|
|
|
|
|
func new_move_actor_as_desired(_delta :float,
|
|
|
|
|
_state :StateAnimatedActor,
|
|
|
|
|
_movement_override_normal := Vector2(0,0)) -> Vector2:
|
|
|
|
|
_movement_override_normal := Vector2(0,0),
|
|
|
|
|
_velocity_override := Vector2(0,0)) -> Vector2:
|
|
|
|
|
## Calculated movement speed.
|
|
|
|
|
var movement_params :Dictionary = {
|
|
|
|
|
"_base_h_move_speed" : _state.horizontal_speed,
|
|
|
|
|
@ -159,7 +160,12 @@ func new_move_actor_as_desired(_delta :float,
|
|
|
|
|
var calc_velocity = Vector2.ZERO
|
|
|
|
|
var calc_acceleration = Vector2.ZERO
|
|
|
|
|
var calc_inertia :Vector2
|
|
|
|
|
calc_inertia.x = abs(velocity.x)
|
|
|
|
|
##TODO: make sure velocity variable exists since we rely on it
|
|
|
|
|
## Calc from the _velocity_override instead of current object velocity
|
|
|
|
|
if _velocity_override.x != 0.0:
|
|
|
|
|
calc_inertia.x = abs(_velocity_override.x)
|
|
|
|
|
else:
|
|
|
|
|
calc_inertia.x = abs(velocity.x)
|
|
|
|
|
##TODO: Only implemented horizontal so far.
|
|
|
|
|
calc_inertia.y = velocity.y
|
|
|
|
|
var calc_inertial_dir = Vector2(sign(velocity.x),sign(velocity.y))
|
|
|
|
|
@ -181,13 +187,25 @@ func new_move_actor_as_desired(_delta :float,
|
|
|
|
|
else:
|
|
|
|
|
move_direction = resolve_move_direction(calc_inertial_dir, desired_movement_vector)
|
|
|
|
|
|
|
|
|
|
calc_acceleration.x = resolve_h_acceleration(movement_params, h_speed, move_direction.x)
|
|
|
|
|
## Which direction will acceleration be applied.
|
|
|
|
|
calc_acceleration.x = resolve_h_acceleration(movement_params, velocity, move_direction.x)
|
|
|
|
|
|
|
|
|
|
## Direction of inertia not equal to move direction
|
|
|
|
|
if calc_inertial_dir.x:
|
|
|
|
|
if calc_inertial_dir.x != sign(move_direction.x):
|
|
|
|
|
## flip the direction of acceleration
|
|
|
|
|
calc_acceleration.x *= -1
|
|
|
|
|
## If inertia is applying in a direction
|
|
|
|
|
# if calc_inertial_dir.x:
|
|
|
|
|
# ## And it doesn't apply in the same direction as our movement direction
|
|
|
|
|
# if calc_inertial_dir.x != sign(move_direction.x):
|
|
|
|
|
# ## Apply the direction of acceleration and apply as friction
|
|
|
|
|
# # Friction allows the inertia to trend toward 0 instead of the
|
|
|
|
|
# # 'To' direction of speed.
|
|
|
|
|
# ##
|
|
|
|
|
# #calc_friction.x = calc_acceleration.x * -1
|
|
|
|
|
# calc_friction.x = calc_acceleration.x
|
|
|
|
|
# calc_acceleration.x = 0.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## We are always moving from h_speed.x towards y at a given rate
|
|
|
|
|
|
|
|
|
|
## if we have a difference of speed
|
|
|
|
|
if h_speed.x != h_speed.y:
|
|
|
|
|
@ -195,8 +213,26 @@ func new_move_actor_as_desired(_delta :float,
|
|
|
|
|
## 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)
|
|
|
|
|
# calc_inertia.x = clamp( calc_inertia.x + (calc_acceleration.x * _delta),
|
|
|
|
|
# h_speed.x , h_speed.y)
|
|
|
|
|
## If there is currently no inertia apply the base h_speed
|
|
|
|
|
if calc_inertia.x == 0.0:
|
|
|
|
|
calc_inertia.x = h_speed.x
|
|
|
|
|
## Apply acceleration
|
|
|
|
|
if h_speed.y > h_speed.x:
|
|
|
|
|
calc_inertia.x = move_toward(calc_inertia.x, h_speed.y, (calc_acceleration.x * _delta))
|
|
|
|
|
else:
|
|
|
|
|
## use of move_toward forcing need to apply negative accel as postitive.
|
|
|
|
|
#calc_inertia.x = move_toward(calc_inertia.x, h_speed.y, abs(calc_acceleration.x * _delta))
|
|
|
|
|
calc_inertia.x = clamp( calc_inertia.x + (calc_acceleration.x * _delta),
|
|
|
|
|
h_speed.y , h_speed.x)
|
|
|
|
|
var foo = 3
|
|
|
|
|
|
|
|
|
|
## Apply friction
|
|
|
|
|
#calc_inertia.x = move_toward(calc_inertia.x, 0, (calc_friction.x * _delta))
|
|
|
|
|
# calc_inertia.x = clamp( calc_inertia.x + (calc_friction.x * _delta),
|
|
|
|
|
# 0 , 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.
|
|
|
|
|
@ -212,7 +248,11 @@ func new_move_actor_as_desired(_delta :float,
|
|
|
|
|
# calc_inertia.x, h_speed.y)
|
|
|
|
|
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:
|
|
|
|
|
## Move back towards the base speed
|
|
|
|
|
# calc_inertia.x = clamp( calc_inertia.x + (calc_acceleration.x * _delta),
|
|
|
|
|
# h_speed.x , h_speed.y)
|
|
|
|
|
|
|
|
|
|
if calc_inertia.x < h_speed.x:
|
|
|
|
|
calc_inertia.x = clamp( calc_inertia.x + ( calc_acceleration.x * _delta),
|
|
|
|
|
calc_inertia.x, h_speed.x)
|
|
|
|
|
else:
|
|
|
|
|
@ -224,12 +264,13 @@ func new_move_actor_as_desired(_delta :float,
|
|
|
|
|
#var friction :Vector2
|
|
|
|
|
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 + ( 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 + ( calc_friction.x * _delta),
|
|
|
|
|
calc_inertia.x, h_speed.x)
|
|
|
|
|
calc_inertia.x = move_toward(calc_inertia.x, h_speed.x, ( calc_friction.x * _delta))
|
|
|
|
|
# if calc_inertia.x > h_speed.x: ## Inertia is higher than the base speed (slow it down)
|
|
|
|
|
# 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 + ( calc_friction.x * _delta),
|
|
|
|
|
# calc_inertia.x, h_speed.x)
|
|
|
|
|
else:
|
|
|
|
|
## no residual acceleration (friction) applies, kill the momentum
|
|
|
|
|
calc_inertia.x = 0.0
|
|
|
|
|
@ -266,7 +307,7 @@ func new_move_actor_as_desired(_delta :float,
|
|
|
|
|
#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}) +
|
|
|
|
|
"H_Speed Fm:{0} To:{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}) +
|
|
|
|
|
@ -294,17 +335,25 @@ func resolve_h_speed(_params :Dictionary) -> Vector2:
|
|
|
|
|
if _params["_base_h_move_speed_modifier"] != 0:
|
|
|
|
|
var speed_differance = base_speed + _params["_base_h_move_speed_modifier"]
|
|
|
|
|
|
|
|
|
|
# if sign(_params["_base_h_move_speed_modifier"]) == -1:
|
|
|
|
|
# return Vector2(speed_differance, base_speed)
|
|
|
|
|
# else:
|
|
|
|
|
# return Vector2(base_speed, speed_differance)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return(Vector2(base_speed, speed_differance))
|
|
|
|
|
## We start at a slower base speed and move upward
|
|
|
|
|
if speed_differance > base_speed:
|
|
|
|
|
return(Vector2(base_speed, speed_differance))
|
|
|
|
|
else:
|
|
|
|
|
## We start at a higher speed and move downward to base
|
|
|
|
|
return(Vector2(speed_differance, base_speed ))
|
|
|
|
|
## Disabled because flipping accel direction may make more sense.
|
|
|
|
|
# if speed_differance > base_speed:
|
|
|
|
|
# return(Vector2(base_speed, speed_differance))
|
|
|
|
|
# else:
|
|
|
|
|
# ## We start at a higher speed and move downward to base
|
|
|
|
|
# return(Vector2(speed_differance, base_speed ))
|
|
|
|
|
# if inertia:
|
|
|
|
|
# return Vector2(0,inertia)
|
|
|
|
|
return Vector2(base_speed,base_speed)
|
|
|
|
|
|
|
|
|
|
func resolve_h_acceleration(_params :Dictionary, _speed :Vector2, _move_direction :float) -> float:
|
|
|
|
|
func resolve_h_acceleration(_params :Dictionary, _inertia :Vector2, _move_direction :float) -> float:
|
|
|
|
|
## TODO: Adjust for jerk, determine if we're currently experiencing accel
|
|
|
|
|
## if a speed difference applies
|
|
|
|
|
var _acceleration :float = 0.0
|
|
|
|
|
@ -312,15 +361,21 @@ func resolve_h_acceleration(_params :Dictionary, _speed :Vector2, _move_directio
|
|
|
|
|
_acceleration = _params["_base_h_move_acceleration"] + _params["_base_h_move_modifier_move_acceleration"]
|
|
|
|
|
else:
|
|
|
|
|
_acceleration = _params["_base_h_move_acceleration"]
|
|
|
|
|
##TODO: Add part where offset acceleration only applies until the inertia equals the offset or whatever
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#_acceleration *= sign(_move_direction)
|
|
|
|
|
## Well this didn't work
|
|
|
|
|
#_acceleration = _params["_base_h_move_acceleration"] + _params["_base_h_move_modifier_move_acceleration"]
|
|
|
|
|
## If the indented movedirection doesn't match our velocity direction
|
|
|
|
|
|
|
|
|
|
if _speed.x < _speed.y:
|
|
|
|
|
return _acceleration
|
|
|
|
|
elif _speed.x > _speed.y:
|
|
|
|
|
if _inertia.x != 0.0 and sign(_inertia.x) != sign(_move_direction):
|
|
|
|
|
return _acceleration * -1
|
|
|
|
|
elif sign(_move_direction) != 0:
|
|
|
|
|
## If no velocity or it matches just return as is.
|
|
|
|
|
return _acceleration
|
|
|
|
|
|
|
|
|
|
# No accel returned unless intended
|
|
|
|
|
return 0.0
|
|
|
|
|
|
|
|
|
|
func resolve_move_direction(_momentum :Vector2,
|
|
|
|
|
@ -334,9 +389,6 @@ func resolve_move_direction(_momentum :Vector2,
|
|
|
|
|
return Vector2(horizontal_movement_direction,0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func adjust_base_movement():
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
## About to DEPR this one for redesigned one above
|
|
|
|
|
func move_actor_as_desired( x_move_direction_override: float = 0):
|
|
|
|
|
var delta:float = physics_delta
|
|
|
|
|
|