godot-plateformer/_player/states/jump.gd

43 lines
1.2 KiB
GDScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

extends LimboState
@onready var root: Normal = %Normal
##TODO:后续把JumpGrace在JumpState也写一下或者直接写到AirBoneState目前的JumpGrace由于只能在Fall触发会卡手
func _setup() -> void:
self.add_event_handler(&"completed_jump",_handler_completed_jump)
func _enter() -> void:
_jump_from_land_check()
##是否要强制重置水平速度。
var f = blackboard.get_var(&"force_reset_jump",false) as bool
var _j = agent.locomotion_comp.jump(f) as bool
get_root().blackboard.set_var(&"is_jumping",true) #标记jump
get_root().blackboard.set_var(&"force_reset_jump",false)#重置强制重置位
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