godot-plateformer/_player/states/wall_jump.gd

40 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
@export var wall_jump_force_time: float = .24
var wall_jump_force_timer: float
func _setup() -> void:
self.add_event_handler(&"completed_jump",_handler_completed_jump)
func _enter() -> void:
agent.locomotion_comp.wall_jump()
wall_jump_force_timer = wall_jump_force_time
get_root().blackboard.set_var(&"lock_direction_changed",true)
func _exit() -> void:
#这里强制重置一下
agent.locomotion_comp.stop_jump()
get_root().blackboard.set_var(&"lock_direction_changed",false)
func _update(delta: float) -> void:
if agent.velocity.y >= 0:
get_root().dispatch(self.EVENT_FINISHED)
var move_dir : float
move_dir = Input.get_axis(&"move_left",&"move_right")
#这里执行一个额外的忽略输入的逻辑,在墙跳的开始阶段,玩家如果存在移动输入,则会被强制归为沿墙壁法向的输入
if wall_jump_force_timer > 0:
wall_jump_force_timer -= delta
#这里的行为是如果当前存在输入则不管是什么方向的都归为法向否则就是0
move_dir = agent.get_wall_normal().x if Input.get_axis(&"move_left",&"move_right") != 0 else 0
agent.locomotion_comp.add_movement_input(move_dir)
func _handler_completed_jump() -> bool:
agent.locomotion_comp.stop_jump()
return true