godot-plateformer/_player/states/jump.gd

43 lines
1.2 KiB
GDScript3
Raw Permalink 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()
2026-01-11 00:57:27 +08:00
##是否要强制重置水平速度。
var f = blackboard.get_var(&"force_reset_jump",false) as bool
var _j = agent.locomotion_comp.jump(f) as bool
2025-12-29 11:54:31 +08:00
get_root().blackboard.set_var(&"is_jumping",true) #标记jump
2026-01-11 00:57:27 +08:00
get_root().blackboard.set_var(&"force_reset_jump",false)#重置强制重置位
2025-12-29 11:54:31 +08:00
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