Movement Cleanup.
This commit is contained in:
parent
05580ee50d
commit
fc29c18552
|
|
@ -156,11 +156,7 @@ enum RANGE_PLACEMENT {
|
||||||
# accepts the state to determine movement, the deltatime, and an optional direction
|
# accepts the state to determine movement, the deltatime, and an optional direction
|
||||||
# Update: Actually should just return movement in PPS
|
# Update: Actually should just return movement in PPS
|
||||||
##
|
##
|
||||||
#var calc_inertia = velocity.abs()
|
|
||||||
#var calc_inertial_dir :Vector2
|
|
||||||
var debug_speed_tracker :Vector2
|
|
||||||
var impulse_applied_dir :float = 0.0
|
|
||||||
var impulse_applied :bool = false
|
|
||||||
## Could these be datatypes or a class? Sure
|
## Could these be datatypes or a class? Sure
|
||||||
var _h_impulse_applied :bool = false
|
var _h_impulse_applied :bool = false
|
||||||
var _h_impulse_speed_tracking :Vector2
|
var _h_impulse_speed_tracking :Vector2
|
||||||
|
|
@ -172,9 +168,6 @@ func new_move_actor_as_desired(_delta :float,
|
||||||
_movement_override_normal := Vector2(0,0),
|
_movement_override_normal := Vector2(0,0),
|
||||||
_velocity_override := Vector2(0,0)) -> Vector2:
|
_velocity_override := Vector2(0,0)) -> Vector2:
|
||||||
|
|
||||||
if _state.name == 'jump':
|
|
||||||
var foo = 2+2 # break
|
|
||||||
|
|
||||||
var calc_velocity = Vector2.ZERO
|
var calc_velocity = Vector2.ZERO
|
||||||
if _velocity_override.x != 0.0:
|
if _velocity_override.x != 0.0:
|
||||||
calc_velocity.x = _velocity_override.x
|
calc_velocity.x = _velocity_override.x
|
||||||
|
|
@ -206,13 +199,6 @@ func new_move_actor_as_desired(_delta :float,
|
||||||
else:
|
else:
|
||||||
move_direction = resolve_move_direction(calc_inertia, desired_movement_vector)
|
move_direction = resolve_move_direction(calc_inertia, desired_movement_vector)
|
||||||
|
|
||||||
##WIP: the impulse logic just doesn't work still, below is another attempt
|
|
||||||
# if impulse_applied_dir != move_direction.x and sign(calc_velocity.x) != impulse_applied_dir:
|
|
||||||
# print("resetting impulse")
|
|
||||||
# impulse_applied = false
|
|
||||||
# impulse_applied_dir = sign(move_direction.x)
|
|
||||||
|
|
||||||
|
|
||||||
var modifier_indicator := ''
|
var modifier_indicator := ''
|
||||||
var movement_parameters :MovementParameters = _state.get_movement_parameters()
|
var movement_parameters :MovementParameters = _state.get_movement_parameters()
|
||||||
if modifier and modifier.is_active:
|
if modifier and modifier.is_active:
|
||||||
|
|
@ -241,6 +227,9 @@ func new_move_actor_as_desired(_delta :float,
|
||||||
var h_range_placement = placement_to_speed_range(calc_velocity.x, h_speed)
|
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)
|
var v_range_placement = placement_to_speed_range(calc_velocity.y, v_speed)
|
||||||
|
|
||||||
|
## 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
|
||||||
|
# should only be allowed once.
|
||||||
## 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
|
||||||
|
|
@ -251,27 +240,11 @@ func new_move_actor_as_desired(_delta :float,
|
||||||
_v_impulse_applied == true ):
|
_v_impulse_applied == true ):
|
||||||
print("resetting V impulse")
|
print("resetting V impulse")
|
||||||
_v_impulse_applied = false
|
_v_impulse_applied = false
|
||||||
## 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
|
|
||||||
# should only be allowed once.
|
|
||||||
|
|
||||||
## Acceleration is always postive because we use the
|
## Acceleration is always postive because we use the
|
||||||
# move toward functions.
|
# move toward functions.
|
||||||
calc_acceleration.x = abs(resolve_h_acceleration(movement_parameters, move_direction.x))
|
calc_acceleration.x = abs(resolve_h_acceleration(movement_parameters, move_direction.x))
|
||||||
|
|
||||||
## Direction of inertia not equal to move direction
|
|
||||||
## 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 = abs(calc_acceleration.x)
|
|
||||||
# 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.
|
##TODO: The Min Max could be augmented to just be h_speed.x and prevent the sliding.
|
||||||
|
|
@ -311,18 +284,10 @@ func new_move_actor_as_desired(_delta :float,
|
||||||
## Move back towards the base speed
|
## Move back towards the base speed
|
||||||
calc_inertia.x = move_toward(calc_inertia.x, h_speed.x, calc_acceleration.x * _delta)
|
calc_inertia.x = move_toward(calc_inertia.x, h_speed.x, calc_acceleration.x * _delta)
|
||||||
|
|
||||||
# if (h_speed != debug_speed_tracker):
|
|
||||||
# print("Inertia SpeedShift: ", debug_speed_tracker, h_speed, (0.0 == -0.0))
|
|
||||||
# debug_speed_tracker = h_speed
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
## inertia is just base speed
|
## inertia is just base speed
|
||||||
calc_inertia.x = h_speed.x
|
calc_inertia.x = h_speed.x
|
||||||
calc_inertial_dir.x = 0.0 # sign(calc_inertia.x)
|
calc_inertial_dir.x = 0.0 # sign(calc_inertia.x)
|
||||||
debug_speed_tracker = h_speed
|
|
||||||
# if move_direction.x == 0:
|
|
||||||
# calc_inertial_dir.x = sign(h_speed.x)
|
|
||||||
|
|
||||||
|
|
||||||
## 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
|
||||||
|
|
@ -354,23 +319,6 @@ func new_move_actor_as_desired(_delta :float,
|
||||||
min(calc_inertia.y, v_speed.y),
|
min(calc_inertia.y, v_speed.y),
|
||||||
max(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
|
||||||
|
|
@ -382,6 +330,7 @@ func new_move_actor_as_desired(_delta :float,
|
||||||
calc_velocity.y = calc_inertia.y
|
calc_velocity.y = calc_inertia.y
|
||||||
calc_velocity.x = calc_inertia.x
|
calc_velocity.x = calc_inertia.x
|
||||||
|
|
||||||
|
if debug_component:
|
||||||
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}) +
|
||||||
|
|
|
||||||
|
|
@ -11,12 +11,12 @@ onready var stamina_component = $"%Stamina_Component"
|
||||||
var state_stamina_cost :Dictionary
|
var state_stamina_cost :Dictionary
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
var state_ref :State
|
#var state_ref :State
|
||||||
var state_name :String
|
#var state_name :String
|
||||||
state_name = 'jump'
|
#state_name = 'jump'
|
||||||
state_ref = get_node(callable_state_machine).get_state_reference(state_name)
|
#state_ref = get_node(callable_state_machine).get_state_reference(state_name)
|
||||||
##TODO Should probably assert here or something.
|
##TODO Should probably assert here or something.
|
||||||
state_ref.connect("state_entered", self, "_on_state_entered_" + state_name)
|
#state_ref.connect("state_entered", self, "_on_state_entered_" + state_name)
|
||||||
parent_request_state_change = funcref(get_node(callable_state_machine), 'check_parent_before_state_change')
|
parent_request_state_change = funcref(get_node(callable_state_machine), 'check_parent_before_state_change')
|
||||||
|
|
||||||
if parent.has_method("use_primary_item"):
|
if parent.has_method("use_primary_item"):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user