2.10 the export annotation

This commit is contained in:
david 2025-02-02 16:09:35 +01:00
parent e2bf9cea50
commit c311181e8b
3 changed files with 31 additions and 6 deletions

View file

@ -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 :(");
}
}
}

View file

@ -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")

View file

@ -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)