godot-plateformer/_player/states/jump.gd

39 lines
1.0 KiB
GDScript3
Raw Normal View History

2025-12-29 11:54:31 +08:00
extends LimboState
@onready var root: Normal = %Normal
2026-01-04 21:21:01 +08:00
##TODO:后续把JumpGrace在JumpState也写一下或者直接写到AirBoneState目前的JumpGrace由于只能在Fall触发会卡手
2025-12-29 11:54:31 +08:00
func _setup() -> void:
self.add_event_handler(&"completed_jump",_handler_completed_jump)
func _enter() -> void:
_jump_from_land_check()
var _j = agent.locomotion_comp.jump() as bool
get_root().blackboard.set_var(&"is_jumping",true) #标记jump
func _exit() -> void:
#这里强制重置一下
agent.locomotion_comp.stop_jump()
func _update(delta: float) -> void:
var move_dir = Input.get_axis(&"move_left",&"move_right")
agent.locomotion_comp.add_movement_input(move_dir)
if agent.velocity.y >= 0:
get_root().dispatch(self.EVENT_FINISHED)
func _handler_completed_jump() -> bool:
agent.locomotion_comp.stop_jump()
return true
func _jump_from_land_check() -> bool:
var last_state = root.get_previous_active_state() as LimboState
if last_state and last_state == root.ground_state :
agent.on_jump()
return true
return false