Major collision detection improvements, more file organization, and added key interactable
This commit is contained in:
@@ -9,20 +9,20 @@ var velocity: Vector2 = Vector2.ZERO
|
||||
func _physics_process(_delta: float) -> void:
|
||||
velocity = Vector2.ZERO
|
||||
|
||||
if player:
|
||||
if player and position.distance_to(player.position) > 1:
|
||||
velocity = position.direction_to(player.position).normalized() * SPEED
|
||||
|
||||
velocity = move_and_slide(velocity)
|
||||
return
|
||||
|
||||
|
||||
func _on_player_detector_area_entered(area: Area2D) -> void:
|
||||
if area.get_parent().name == 'Player':
|
||||
player = area.get_parent()
|
||||
func _on_player_detector_body_entered(body: Node) -> void:
|
||||
if 'player' in body.get_groups():
|
||||
player = body
|
||||
return
|
||||
|
||||
|
||||
func _on_player_detector_area_exited(area: Area2D):
|
||||
if area.get_parent().name == 'Player':
|
||||
func _on_player_detector_body_exited(body: Node) -> void:
|
||||
if 'player' in body.get_groups():
|
||||
player = null
|
||||
return
|
||||
|
@@ -1,10 +1,14 @@
|
||||
[gd_scene load_steps=7 format=2]
|
||||
[gd_scene load_steps=8 format=2]
|
||||
|
||||
[ext_resource path="res://Resources/Level_5_Enemy_Glowing_Ghost_Occluder.tres" type="OccluderPolygon2D" id=1]
|
||||
[ext_resource path="res://Sprites/Assets/Light.png" type="Texture" id=2]
|
||||
[ext_resource path="res://Sprites/Enemies/Glowing_Ghost.png" type="Texture" id=3]
|
||||
[ext_resource path="res://Enemies/Glowing Ghost.gd" type="Script" id=4]
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id=3]
|
||||
radius = 1.5
|
||||
height = 3.0
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id=1]
|
||||
radius = 3.0
|
||||
height = 2.0
|
||||
@@ -12,18 +16,29 @@ height = 2.0
|
||||
[sub_resource type="CircleShape2D" id=2]
|
||||
radius = 50.0
|
||||
|
||||
[node name="Glowing Ghost" type="KinematicBody2D" groups=["enemies"]]
|
||||
collision_layer = 2
|
||||
[node name="Glowing Ghost" type="KinematicBody2D" groups=["enemy"]]
|
||||
collision_layer = 4
|
||||
collision_mask = 5
|
||||
script = ExtResource( 4 )
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="."]
|
||||
light_mask = 4
|
||||
position = Vector2( 0, -3 )
|
||||
texture = ExtResource( 3 )
|
||||
offset = Vector2( 0, 0.5 )
|
||||
|
||||
[node name="Hitbox" type="CollisionShape2D" parent="."]
|
||||
[node name="Collision" type="CollisionShape2D" parent="."]
|
||||
visible = false
|
||||
position = Vector2( 0, -3 )
|
||||
rotation = 1.5708
|
||||
shape = SubResource( 3 )
|
||||
|
||||
[node name="Hitbox" type="Area2D" parent="." groups=["enemy_hitbox"]]
|
||||
collision_layer = 4
|
||||
collision_mask = 2
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox"]
|
||||
visible = false
|
||||
position = Vector2( 0, -2.5 )
|
||||
shape = SubResource( 1 )
|
||||
|
||||
[node name="Player Detector" type="Area2D" parent="."]
|
||||
@@ -36,22 +51,22 @@ monitorable = false
|
||||
visible = false
|
||||
shape = SubResource( 2 )
|
||||
|
||||
[node name="Light2D" type="Light2D" parent="."]
|
||||
[node name="Light" type="Light2D" parent="."]
|
||||
scale = Vector2( 0.5, 0.5 )
|
||||
texture = ExtResource( 2 )
|
||||
color = Color( 0.984314, 0.94902, 0.211765, 0.392157 )
|
||||
energy = 2.0
|
||||
range_item_cull_mask = 11
|
||||
|
||||
[node name="Light2DEyes" type="Light2D" parent="."]
|
||||
[node name="Eyes" type="Light2D" parent="."]
|
||||
scale = Vector2( 0.1, 0.1 )
|
||||
texture = ExtResource( 2 )
|
||||
offset = Vector2( 5, -40 )
|
||||
offset = Vector2( 5, -35 )
|
||||
range_item_cull_mask = 4
|
||||
|
||||
[node name="LightOccluder2D" type="LightOccluder2D" parent="."]
|
||||
[node name="Occluder" type="LightOccluder2D" parent="."]
|
||||
show_behind_parent = true
|
||||
occluder = ExtResource( 1 )
|
||||
|
||||
[connection signal="area_entered" from="Player Detector" to="." method="_on_player_detector_area_entered"]
|
||||
[connection signal="area_exited" from="Player Detector" to="." method="_on_player_detector_area_exited"]
|
||||
[connection signal="body_entered" from="Player Detector" to="." method="_on_player_detector_body_entered"]
|
||||
[connection signal="body_exited" from="Player Detector" to="." method="_on_player_detector_body_exited"]
|
||||
|
Reference in New Issue
Block a user