Revert changes to state_animated_actor

This commit is contained in:
Nitsud Yarg 2024-07-04 11:33:51 -07:00
parent 0af4a19828
commit 402ce4456f

View File

@ -23,7 +23,7 @@ export var move_speed_modifier: float = 0
export var move_modifier_move_acceleration: float = 0 export var move_modifier_move_acceleration: float = 0
export var jerk_factor: float = 0 export var jerk_factor: float = 0
#var adjusted_move_speed: float var adjusted_move_speed: float
var jerk: float var jerk: float
var physics_modifier :StateModifier var physics_modifier :StateModifier
@ -168,7 +168,7 @@ func enter() -> void:
update_animation() update_animation()
# Reset movespeed counters # Reset movespeed counters
move_component.momentum.x = move_speed_modifier adjusted_move_speed = move_speed_modifier
jerk = 0 jerk = 0
return return
@ -260,16 +260,12 @@ func process_physics(_delta: float) -> State:
# if animations.frames.get_animation_loop(animations.animation) == false: # if animations.frames.get_animation_loop(animations.animation) == false:
# animation_index += 1 # animation_index += 1
func move_actor_as_desired(delta: float, x_impulse_direction: float = 0): func move_actor_as_desired(delta: float, x_direction: float = 0):
var _move_acceleration:float = 0.0
var _move_speed = move_speed var _move_speed = move_speed
var _move_speed_modifier = move_speed_modifier var _move_speed_modifier = move_speed_modifier
# var _move_modifier_move_acceleration = move_modifier_move_acceleration var _move_modifier_move_acceleration = move_modifier_move_acceleration
# var _move_acceleration = move_acceleration var _move_acceleration = move_acceleration
_move_acceleration += move_modifier_move_acceleration
_move_acceleration += move_acceleration
var _jerk_factor = jerk_factor var _jerk_factor = jerk_factor
var _gravity = gravity var _gravity = gravity
@ -282,43 +278,24 @@ func move_actor_as_desired(delta: float, x_impulse_direction: float = 0):
_move_speed = mod_props.move_speed _move_speed = mod_props.move_speed
_move_speed_modifier += mod_props.move_speed_modifier _move_speed_modifier += mod_props.move_speed_modifier
_move_acceleration += mod_props.move_acceleration _move_acceleration += mod_props.move_acceleration
# _move_modifier_move_acceleration += mod_props.move_modifier_move_acceleration _move_modifier_move_acceleration += mod_props.move_modifier_move_acceleration
_move_acceleration += mod_props.move_modifier_move_acceleration
_jerk_factor += mod_props.jerk_factor _jerk_factor += mod_props.jerk_factor
# else: # else:
# UiManager.debug_text = '' # UiManager.debug_text = ''
if x_impulse_direction == 0:
x_impulse_direction = 1
# Help to preserve momentum I guess
if _move_acceleration != 0:
move_component.acceleration.x = _move_acceleration #* x_impulse_direction
# Assuming adjusted_move_speed is set to the mood speed modifier on state entry # Assuming adjusted_move_speed is set to the mood speed modifier on state entry
# Move speed is the base speed plus the modifier minus the decay adjusted for time # Move speed is the base speed plus the modifier minus the decay adjusted for time
jerk += _jerk_factor * delta jerk += _jerk_factor * delta
move_component.momentum.x += move_component.acceleration.x * delta adjusted_move_speed += _move_modifier_move_acceleration * delta
#Another crappy normalization hack #Another crappy normalization hack
if move_component.momentum.x > _move_speed_modifier and _move_speed_modifier > 0: if adjusted_move_speed > _move_speed_modifier and _move_speed_modifier > 0:
move_component.momentum.x = _move_speed_modifier adjusted_move_speed = _move_speed_modifier
#move_component.acceleration.x = 0 elif adjusted_move_speed < _move_speed_modifier and _move_speed_modifier < 0:
elif move_component.momentum.x < _move_speed_modifier and _move_speed_modifier < 0: adjusted_move_speed = _move_speed_modifier
move_component.momentum.x = _move_speed_modifier
#move_component.acceleration.x = 0
# Crappy momentum shutdown routines when the modifier doesn't apply
if _move_speed_modifier == 0: if _move_speed_modifier == 0:
if move_component.momentum.x > 0 and move_component.acceleration.x > 0: adjusted_move_speed = 0
move_component.momentum.x = 0
move_component.acceleration.x = 0
elif move_component.momentum.x < 0 and move_component.acceleration.x < 0:
move_component.momentum.x = 0
move_component.acceleration.x = 0
var new_move_speed = (_move_speed + _move_speed_modifier ) + move_component.momentum.x + jerk var new_move_speed = (_move_speed + _move_speed_modifier ) + (_move_acceleration * delta) + adjusted_move_speed + jerk
# var new_move_speed = (_move_speed + _move_speed_modifier ) + (_move_acceleration * delta) + move_component.momentum.x + jerk
# A really crappy normalization to prevent modifying past the base move speed. # A really crappy normalization to prevent modifying past the base move speed.
@ -331,8 +308,8 @@ func move_actor_as_desired(delta: float, x_impulse_direction: float = 0):
new_move_speed = _move_speed new_move_speed = _move_speed
#adjusted_move_speed = 0 #adjusted_move_speed = 0
else: else:
#if new_move_speed != move_speed: if new_move_speed != move_speed:
UiManager.debug_text = "S:" + str(round(new_move_speed)) + ",M" + str(round(move_component.momentum.x)) + ",A" + str(round(move_component.acceleration.x)) # str(round(jerk)) UiManager.debug_text = str(round(adjusted_move_speed)) + "," + str(round(new_move_speed)) + "," + str(round(jerk))
#print(adjusted_move_speed, ",", new_move_speed, ",", jerk) #print(adjusted_move_speed, ",", new_move_speed, ",", jerk)
#print(new_move_speed, " ", adjusted_move_speed) #print(new_move_speed, " ", adjusted_move_speed)
@ -340,7 +317,10 @@ func move_actor_as_desired(delta: float, x_impulse_direction: float = 0):
move_component.velocity.y += _gravity * delta move_component.velocity.y += _gravity * delta
#parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1)) #parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
#print(speed_multiplier) #print(speed_multiplier)
move_component.velocity.x = move_component.desired_movement_vector.x * new_move_speed if (x_direction != 0):
move_component.velocity.x = x_direction * new_move_speed
else:
move_component.velocity.x = move_component.desired_movement_vector.x * new_move_speed
move_component.velocity = parent.move_and_slide(move_component.velocity, Vector2(0, -1)) move_component.velocity = parent.move_and_slide(move_component.velocity, Vector2(0, -1))