79 lines
2.8 KiB
GDScript
79 lines
2.8 KiB
GDScript
extends StateAnimatedActor
|
|
|
|
export (NodePath) var fall_node
|
|
export (NodePath) var idle_node
|
|
export (NodePath) var attack_node
|
|
export (NodePath) var jump_node
|
|
|
|
onready var jump_state: State = get_node(jump_node)
|
|
onready var fall_state: State = get_node(fall_node)
|
|
onready var idle_state: State = get_node(idle_node)
|
|
onready var attack_state: State = get_node(attack_node)
|
|
|
|
#var speed_decay_rate := 1.0
|
|
|
|
func process_physics(delta: float) -> State:
|
|
|
|
# if move_component.wants_shoot():
|
|
# return attack_state
|
|
|
|
if move_component.wants_jump():
|
|
return jump_state
|
|
|
|
# Move the last direction we were facing.
|
|
move_actor_as_desired(delta, parent.transform.x.x)
|
|
# # 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
|
|
# jerk += jerk_factor * delta
|
|
# adjusted_move_speed += move_modifier_move_acceleration * delta
|
|
# var new_move_speed = move_speed + (move_acceleration * delta) + adjusted_move_speed + jerk
|
|
#
|
|
# # A really crappy normalization to prevent modifying past the base move speed.
|
|
# if move_speed_modifier > 0 and new_move_speed < move_speed: # positive modifier
|
|
# #print("nope1")
|
|
# new_move_speed = move_speed
|
|
# elif move_speed_modifier < 0 and new_move_speed > move_speed: # negative modifier
|
|
# #print("nope2")
|
|
# new_move_speed = move_speed
|
|
# else:
|
|
# 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(new_move_speed, " ", adjusted_move_speed)
|
|
#
|
|
# move_component.velocity.y += gravity * delta
|
|
# #parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
|
# #print(speed_multiplier)
|
|
# move_component.velocity.x = parent.transform.x.x * new_move_speed
|
|
# move_component.velocity = parent.move_and_slide(move_component.velocity, Vector2(0, -1))
|
|
|
|
## Trying a whole new model
|
|
# var new_move_speed = move_speed * speed_multiplier
|
|
# if speed_multiplier > 1.0:
|
|
# print("PPS: ", new_move_speed * delta)
|
|
# speed_multiplier -= delta * (speed_decay_rate * speed_multiplier)
|
|
# #speed_decay_rate += delta * speed_decay_rate
|
|
#
|
|
# elif speed_multiplier < 1.0:
|
|
# speed_multiplier += delta * (speed_decay_rate * speed_multiplier)
|
|
# #speed_decay_rate += delta * speed_decay_rate
|
|
#
|
|
# # Deadzone
|
|
# if speed_multiplier < 1.1 and speed_multiplier > 0.9:
|
|
# speed_multiplier = 1.0
|
|
#
|
|
# move_component.velocity.y += gravity * delta
|
|
# #parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
|
# #print(speed_multiplier)
|
|
# move_component.velocity.x = parent.transform.x.x * new_move_speed
|
|
# move_component.velocity = parent.move_and_slide(move_component.velocity, Vector2(0, -1))
|
|
|
|
|
|
if move_component.velocity.x == 0.0 or animations.playing == false:
|
|
if !parent.is_on_floor():
|
|
return fall_state
|
|
else:
|
|
return idle_state
|
|
|
|
return null
|