mirror of
https://github.com/GDQuest/godot-platformer-2d.git
synced 2026-07-18 00:44:53 +00:00
Merge pull request #83 from henriiquecampos/wall-from-jump-fix
Fix Wall State issues
This commit is contained in:
commit
e3dd2dd488
4 changed files with 37 additions and 5 deletions
|
|
@ -11,6 +11,7 @@ onready var skin: Position2D = $Skin
|
|||
onready var stats: Stats = $Stats
|
||||
onready var collider: CollisionShape2D = $CollisionShape2D
|
||||
onready var hitbox: Area2D = $HitBox
|
||||
onready var wall_detector: RayCast2D = $WallDetector
|
||||
|
||||
const FLOOR_NORMAL: = Vector2.UP
|
||||
|
||||
|
|
|
|||
|
|
@ -34,9 +34,16 @@ shape = SubResource( 1 )
|
|||
position = Vector2( 0, -30 )
|
||||
|
||||
[node name="LedgeDetector" parent="." instance=ExtResource( 3 )]
|
||||
is_active = true
|
||||
ray_length = 30.0
|
||||
|
||||
[node name="FloorDetector" parent="." instance=ExtResource( 4 )]
|
||||
|
||||
[node name="WallDetector" type="RayCast2D" parent="."]
|
||||
position = Vector2( 0, -31.1111 )
|
||||
cast_to = Vector2( 100, 0 )
|
||||
collision_mask = 2
|
||||
|
||||
[node name="CameraAnchorDetector" parent="." instance=ExtResource( 5 )]
|
||||
editor/display_folded = true
|
||||
|
||||
|
|
@ -46,6 +53,10 @@ remote_path = NodePath("../../CameraRig")
|
|||
[node name="CameraRig" parent="." instance=ExtResource( 6 )]
|
||||
editor/display_folded = true
|
||||
|
||||
[node name="ShakingCamera" parent="CameraRig" index="0"]
|
||||
DAMP_EASING = 1.0
|
||||
is_shaking = false
|
||||
|
||||
[node name="Skin" parent="." instance=ExtResource( 7 )]
|
||||
|
||||
[node name="StateMachine" type="Node" parent="."]
|
||||
|
|
@ -75,13 +86,16 @@ wait_time = 0.1
|
|||
one_shot = true
|
||||
|
||||
[node name="Wall" type="Node" parent="StateMachine/Move"]
|
||||
editor/display_folded = true
|
||||
script = ExtResource( 13 )
|
||||
|
||||
[node name="JumpDelay" type="Timer" parent="StateMachine/Move/Wall"]
|
||||
wait_time = 0.2
|
||||
one_shot = true
|
||||
|
||||
[node name="FallDelay" type="Timer" parent="StateMachine/Move/Wall"]
|
||||
wait_time = 0.05
|
||||
one_shot = true
|
||||
|
||||
[node name="Ledge" type="Node" parent="StateMachine"]
|
||||
script = ExtResource( 14 )
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ func physics_process(delta: float) -> void:
|
|||
elif owner.ledge_detector.is_against_ledge(sign(move.velocity.x)):
|
||||
_state_machine.transition_to("Ledge", {move_state = move})
|
||||
|
||||
if owner.is_on_wall():
|
||||
if owner.is_on_wall() and move.velocity.y > 0:
|
||||
var wall_normal: float = owner.get_slide_collision(0).normal.x
|
||||
_state_machine.transition_to("Move/Wall", {"normal": wall_normal, "velocity": move.velocity})
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
extends State
|
||||
|
||||
onready var jump_delay: Timer = $JumpDelay
|
||||
onready var fall_delay: Timer = $FallDelay
|
||||
|
||||
export var slide_acceleration: = 500.0
|
||||
export var max_slide_speed: = 400.0
|
||||
|
|
@ -11,16 +12,21 @@ var _velocity: = Vector2.ZERO
|
|||
var _wall_normal: = -1
|
||||
|
||||
|
||||
func setup(player: KinematicBody2D, state_machine: Node) -> void:
|
||||
.setup(player, state_machine)
|
||||
func _ready() -> void:
|
||||
jump_delay.connect("timeout", self, "_on_JumpDelay_timeout")
|
||||
fall_delay.connect("timeout", self, "_on_FallDelay_timeout")
|
||||
|
||||
|
||||
|
||||
func enter(msg: Dictionary = {}) -> void:
|
||||
_wall_normal = msg.normal
|
||||
_velocity = msg.velocity
|
||||
if _velocity.y < max_slide_speed:
|
||||
_velocity.y = 0.0
|
||||
|
||||
var wall_detector_length: float = owner.wall_detector.cast_to.length()
|
||||
var wall_direction: = -_wall_normal
|
||||
owner.wall_detector.cast_to = Vector2(wall_direction * wall_detector_length, 0)
|
||||
owner.wall_detector.enabled = true
|
||||
|
||||
|
||||
func physics_process(delta: float) -> void:
|
||||
|
|
@ -32,6 +38,12 @@ func physics_process(delta: float) -> void:
|
|||
|
||||
if owner.is_on_floor():
|
||||
_state_machine.transition_to("Move/Idle")
|
||||
|
||||
if not owner.wall_detector.is_colliding():
|
||||
if fall_delay.is_stopped():
|
||||
fall_delay.start()
|
||||
else:
|
||||
fall_delay.stop()
|
||||
|
||||
|
||||
func unhandled_input(event: InputEvent) -> void:
|
||||
|
|
@ -47,7 +59,12 @@ func unhandled_input(event: InputEvent) -> void:
|
|||
|
||||
func exit() -> void:
|
||||
_velocity = Vector2.ZERO
|
||||
owner.wall_detector.enabled = false
|
||||
|
||||
|
||||
func _on_JumpDelay_timeout() -> void:
|
||||
_state_machine.transition_to("Move/Air", {"velocity": _velocity.y})
|
||||
|
||||
|
||||
func _on_FallDelay_timeout() -> void:
|
||||
_state_machine.transition_to("Move/Air", {"velocity": _velocity.y})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue