Added high wall rays

This commit is contained in:
2026-02-13 00:55:15 +03:00
parent 0dff01da11
commit ebc0133a82
16 changed files with 65 additions and 31 deletions
+5 -2
View File
@@ -15,8 +15,11 @@ var target_x := 0.0
@onready var sprite : AnimatedSprite2D = $CultistSprite
@onready var left_wall_ray : RayCast2D = $%LeftWallRay
@onready var right_wall_ray : RayCast2D = $%RightWallRay
@onready var left_wall_high_ray : RayCast2D = $WallCheckHigh/LeftWallRay
@onready var right_wall_high_ray : RayCast2D = $WallCheckHigh/RightWallRay
@onready var left_wall_low_ray : RayCast2D = $WallCheckLow/LeftWallRay
@onready var right_wall_low_ray : RayCast2D = $WallCheckLow/RightWallRay
@onready var left_player_close_ray : RayCast2D = $%LeftPlayerCloseRay
@onready var right_player_close_ray : RayCast2D = $%RightPlayerCloseRay
+16 -9
View File
@@ -34,19 +34,26 @@ script = ExtResource("1_2wrno")
position = Vector2(0, 2)
shape = SubResource("CapsuleShape2D_mocsw")
[node name="WallCheck" type="Node2D" parent="." unique_id=782156094]
position = Vector2(0, 9)
[node name="WallCheckHigh" type="Node2D" parent="." unique_id=1697845810]
position = Vector2(0, -8)
[node name="LeftWallRay" type="RayCast2D" parent="WallCheck" unique_id=521416854]
unique_name_in_owner = true
[node name="LeftWallRay" type="RayCast2D" parent="WallCheckHigh" unique_id=1026693538]
target_position = Vector2(-16, 0)
[node name="RightWallRay" type="RayCast2D" parent="WallCheck" unique_id=1457669135]
unique_name_in_owner = true
[node name="RightWallRay" type="RayCast2D" parent="WallCheckHigh" unique_id=1129233918]
target_position = Vector2(16, 0)
[node name="WallCheckLow" type="Node2D" parent="." unique_id=782156094]
position = Vector2(0, 9)
[node name="LeftWallRay" type="RayCast2D" parent="WallCheckLow" unique_id=521416854]
target_position = Vector2(-16, 0)
[node name="RightWallRay" type="RayCast2D" parent="WallCheckLow" unique_id=1457669135]
target_position = Vector2(16, 0)
[node name="PlayerCloseCheck" type="Node2D" parent="." unique_id=1593775088]
position = Vector2(0, 9)
position = Vector2(0, -8)
[node name="LeftPlayerCloseRay" type="RayCast2D" parent="PlayerCloseCheck" unique_id=947570027]
unique_name_in_owner = true
@@ -59,7 +66,7 @@ target_position = Vector2(48, 0)
collision_mask = 0
[node name="PlayerDistantCheck" type="Node2D" parent="." unique_id=1597489123]
position = Vector2(0, 9)
position = Vector2(0, -8)
[node name="LeftPlayerDistantRay" type="RayCast2D" parent="PlayerDistantCheck" unique_id=1491085518]
unique_name_in_owner = true
@@ -132,7 +139,7 @@ cultist = NodePath("../..")
[node name="ChaseRightState" parent="CultistStateMachine" unique_id=383038915 node_paths=PackedStringArray("look_around_state", "jump_state", "fall_state", "cultist") instance=ExtResource("5_tu2pi")]
script = ExtResource("14_cqp7f")
look_around_state = NodePath("../LookAroundState")
jump_state = NodePath(".")
jump_state = NodePath("../JumpRightState")
fall_state = NodePath("../FallState")
cultist = NodePath("../..")
+1 -1
View File
@@ -391,5 +391,5 @@ animations = [{
[node name="CultistSprite" type="AnimatedSprite2D" unique_id=351120861]
material = SubResource("ShaderMaterial_vecdo")
sprite_frames = SubResource("SpriteFrames_2wrno")
animation = &"fall_left"
animation = &"idle"
script = ExtResource("3_ef0vi")
@@ -3,7 +3,8 @@ extends CultistChaseState
func init() -> void:
_direction = DIRECTION_LEFT
_wall_ray_cast = cultist.left_wall_ray
_wall_high_ray_cast = cultist.left_wall_high_ray
_wall_low_ray_cast = cultist.left_wall_low_ray
_player_ray_cast = cultist.left_player_distant_ray
@@ -3,7 +3,8 @@ extends CultistChaseState
func init() -> void:
_direction = DIRECTION_RIGHT
_wall_ray_cast = cultist.right_wall_ray
_wall_high_ray_cast = cultist.right_wall_high_ray
_wall_low_ray_cast = cultist.right_wall_low_ray
_player_ray_cast = cultist.right_player_distant_ray
@@ -15,9 +15,9 @@ func physics_process(delta: float) -> void:
if player != null:
cultist.target_x = player.position.x
if _is_target_reached():
if _is_target_reached() or _wall_high_ray_cast.is_colliding():
switch_state.emit(look_around_state)
elif _wall_ray_cast.is_colliding():
elif _wall_low_ray_cast.is_colliding():
switch_state.emit(jump_state)
else:
cultist.update_x_velocity(_direction, cultist.MAX_CHASE_SPEED, delta)
@@ -12,7 +12,7 @@ var state_by_ray_cast : Dictionary[RayCast2D, CultistState]
func enter() -> void:
cultist.sprite.animation_finished.connect(_on_animation_finished, CONNECT_ONE_SHOT)
cultist.sprite.animation_finished.connect(_on_animation_finished)
cultist.sprite.play(CultistSprite.LOOK_AROUND_ANIMATIONS.pick_random())
cultist.velocity = Vector2.ZERO
cultist._set_ray_cast_enable(cultist.left_player_close_ray, true)
@@ -36,6 +36,7 @@ func physics_process(_delta: float) -> void:
func exit() -> void:
cultist.sprite.animation_finished.disconnect(_on_animation_finished)
cultist._set_ray_cast_enable(cultist.left_player_close_ray, false)
cultist._set_ray_cast_enable(cultist.right_player_close_ray, false)
@@ -9,7 +9,9 @@ extends CultistState
@warning_ignore("unused_private_class_variable")
var _direction := 0
@warning_ignore("unused_private_class_variable")
var _wall_ray_cast : RayCast2D
var _wall_high_ray_cast : RayCast2D
@warning_ignore("unused_private_class_variable")
var _wall_low_ray_cast : RayCast2D
var _player_ray_cast : RayCast2D
@@ -3,7 +3,8 @@ extends CultistWalkState
func init() -> void:
_direction = DIRECTION_LEFT
_wall_ray_cast = cultist.left_wall_ray
_wall_high_ray_cast = cultist.left_wall_high_ray
_wall_low_ray_cast = cultist.left_wall_low_ray
_player_ray_cast = cultist.left_player_distant_ray
@@ -3,7 +3,8 @@ extends CultistWalkState
func init() -> void:
_direction = DIRECTION_RIGHT
_wall_ray_cast = cultist.right_wall_ray
_wall_high_ray_cast = cultist.right_wall_high_ray
_wall_low_ray_cast = cultist.right_wall_low_ray
_player_ray_cast = cultist.right_player_distant_ray
@@ -15,7 +15,7 @@ func physics_process(delta: float) -> void:
if player != null:
switch_state.emit(chase_state)
else:
if _wall_ray_cast.is_colliding():
if _wall_low_ray_cast.is_colliding() or _wall_high_ray_cast.is_colliding():
var stream := SoundManager.sfx_stream_player_lost
SoundManager.play_sfx_stream(stream, cultist.global_position)
switch_state.emit(another_direction_walk_state)