43 lines
1.2 KiB
GDScript
43 lines
1.2 KiB
GDScript
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
|