Add CollisionDetection with Asteroids to PlayerShip

pull/26/head
Sascha 2023-10-30 22:10:24 +07:00
parent 505290eaab
commit 6216001b0b
2 changed files with 11 additions and 6 deletions

@ -9,7 +9,7 @@
[ext_resource type="PackedScene" uid="uid://ck31g3hvggoh" path="res://Packed-Scenes/LaserBeam.tscn" id="9_kbdnc"]
[sub_resource type="SphereShape3D" id="SphereShape3D_330dr"]
radius = 0.87
radius = 0.9
[node name="PlayerShip" type="Node3D" node_paths=PackedStringArray("cpulaser", "gpulaser", "jet", "PlayerRb", "shots", "healthBar")]
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74227e-08, 0, -1, 0, 0, 0)
@ -17,7 +17,7 @@ script = ExtResource("1_cpbf1")
cpulaser = NodePath("")
explosion = ExtResource("2_13dyf")
gpulaser = NodePath("")
jet = NodePath("RigidBody3D/CollisionShape3D/Jet")
jet = NodePath("RigidBody3D/Jet")
laser = ExtResource("9_kbdnc")
PlayerRb = NodePath("RigidBody3D")
shots = NodePath("Shots")
@ -30,22 +30,22 @@ gravity_scale = 0.0
[node name="CollisionShape3D" type="CollisionShape3D" parent="RigidBody3D"]
shape = SubResource("SphereShape3D_330dr")
[node name="PlayerShipMesh" type="MeshInstance3D" parent="RigidBody3D/CollisionShape3D"]
[node name="PlayerShipMesh" type="MeshInstance3D" parent="RigidBody3D"]
transform = Transform3D(0.01, 0, 0, 0, 0, -0.01, 0, 0.01, 0, 0, -0.0836085, 0)
gi_mode = 2
mesh = ExtResource("3_716so")
skeleton = NodePath("")
surface_material_override/0 = ExtResource("4_oxh4m")
[node name="Jet" type="Node3D" parent="RigidBody3D/CollisionShape3D"]
[node name="Jet" type="Node3D" parent="RigidBody3D"]
visible = false
[node name="JetCore" type="Sprite3D" parent="RigidBody3D/CollisionShape3D/Jet"]
[node name="JetCore" type="Sprite3D" parent="RigidBody3D/Jet"]
transform = Transform3D(1, -3.55271e-14, 3.82137e-15, 3.82137e-15, 4.37114e-08, -1, 3.55271e-14, 1, 4.37114e-08, 0, 0.01, -1.392)
shaded = true
texture = ExtResource("5_034vf")
[node name="JetFlare" type="Sprite3D" parent="RigidBody3D/CollisionShape3D/Jet"]
[node name="JetFlare" type="Sprite3D" parent="RigidBody3D/Jet"]
transform = Transform3D(1, -2.84217e-14, 3.82137e-15, 3.82137e-15, 4.37114e-08, -1, 2.84217e-14, 1, 4.37114e-08, 0, -0.01, -1.392)
shaded = true
texture = ExtResource("4_87x8f")

@ -75,10 +75,15 @@ public partial class PlayerShip : Node3D {
KinematicCollision3D collision = PlayerRb.MoveAndCollide(moveDir * (float)delta);
if (collision?.GetCollider() is Node3D collider) {
Node3D parent = collider.GetParent<Node3D>();
Vector3 collisionPosition = collision.GetPosition();
switch (parent) {
case GameArea:
GD.Print($"PlayerShip hits GameArea");
break;
case Asteroid asteroid:
Explode(collisionPosition);
asteroid.Explode(collisionPosition);
break;
}
}
}