diff --git a/scenes/characters/Player.cs b/scenes/characters/Player.cs index 63ebb5c..0b03f56 100644 --- a/scenes/characters/Player.cs +++ b/scenes/characters/Player.cs @@ -2,14 +2,25 @@ using Godot; using System; public partial class Player : RigidBody3D -{ - private static Vector3 ZLeft = new Vector3(0.0f, 0.0f, 100.0f); - private static Vector3 ZRight = new Vector3(0.0f, 0.0f, -100.0f); +{ + [Export(PropertyHint.Range, "750.0, 3000.0")] + float thrust = 1000.0f; // The amount of thrust the players has, in newtons + [Export(PropertyHint.Range, "50.0, 200.0")] + float torque = 100.0f; // The amount of torque the player has, in newton meters + private Vector3 ZLeft; + private Vector3 ZRight; + + public override void _Ready() + { + BodyEntered += OnPlayerCollision; + ZLeft = new Vector3(0, 0, torque); + ZRight = new Vector3(0, 0, -torque); + } public override void _Process(double delta) { float fd = (float)delta; if (Input.IsActionPressed("boost")){ - ApplyCentralForce(Basis.Y * fd * 1000.0f); + ApplyCentralForce(Basis.Y * fd * thrust); } if (Input.IsActionPressed("rotate_left")){ ApplyTorque(ZLeft * fd); @@ -18,4 +29,16 @@ public partial class Player : RigidBody3D ApplyTorque(ZRight * fd); } } + + private void OnPlayerCollision(Node body) + { + if (body.GetGroups().Contains("Goal")) + { + GD.Print("Player landed on the landing pad"); + } + if (body.GetGroups().Contains("Hazard")) + { + GD.Print("Player crashed on the floor :("); + } + } } diff --git a/scenes/characters/player.tscn b/scenes/characters/player.tscn index 61ca7a7..7b1f716 100644 --- a/scenes/characters/player.tscn +++ b/scenes/characters/player.tscn @@ -10,6 +10,8 @@ axis_lock_linear_z = true axis_lock_angular_x = true axis_lock_angular_y = true +contact_monitor = true +max_contacts_reported = 10 linear_damp = 1.0 angular_damp = 3.0 script = ExtResource("1_fr1bo") diff --git a/scenes/levels/level_1.tscn b/scenes/levels/level_1.tscn index 4ed0e2d..0d07882 100644 --- a/scenes/levels/level_1.tscn +++ b/scenes/levels/level_1.tscn @@ -33,7 +33,7 @@ environment = SubResource("Environment_mlv3m") transform = Transform3D(-0.866025, -0.433013, 0.25, 0, 0.5, 0.866025, -0.5, 0.75, -0.433013, 0, 0, 0) shadow_enabled = true -[node name="Floor" type="CSGBox3D" parent="."] +[node name="Floor" type="CSGBox3D" parent="." groups=["Hazard"]] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -4, 0) use_collision = true size = Vector3(30, 8, 5) @@ -45,7 +45,7 @@ use_collision = true size = Vector3(2, 0.4, 2) material = SubResource("StandardMaterial3D_5641g") -[node name="LandingPad" type="CSGBox3D" parent="."] +[node name="LandingPad" type="CSGBox3D" parent="." groups=["Goal"]] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 10, 0, 0) use_collision = true size = Vector3(2, 0.4, 2)