Make test thruster work

This commit is contained in:
Yuki Kitagawa 2024-10-23 23:16:02 +08:00
parent 1b76cb3d82
commit fb666f4d81

View File

@ -25,16 +25,18 @@ public partial class TestThruster : RigidBody3D
public override void _Process(double delta) public override void _Process(double delta)
{ {
float throttleStep = 0.2f * (float)delta;
if (Input.IsKeyPressed(Key.Shift)) if (Input.IsKeyPressed(Key.Shift))
{ {
Throttle += 0.1f * (float)delta; Throttle += throttleStep;
} }
else if (Input.IsKeyPressed(Key.Ctrl)) else if (Input.IsKeyPressed(Key.Ctrl))
{ {
Throttle -= 0.1f * (float)delta; Throttle -= throttleStep;
} }
torque = Vector3.Zero; var torque = Vector3.Zero;
float torqueStep = 0.1f;
if (Input.IsKeyPressed(Key.W)) if (Input.IsKeyPressed(Key.W))
{ {
torque += new Vector3(-1.0f, 0.0f, 0.0f); // Forward (X-) torque += new Vector3(-1.0f, 0.0f, 0.0f); // Forward (X-)
@ -59,7 +61,8 @@ public partial class TestThruster : RigidBody3D
{ {
torque += new Vector3(0.0f, -1.0f, 0.0f); // Down (Y-) torque += new Vector3(0.0f, -1.0f, 0.0f); // Down (Y-)
} }
torque *= 0.01f; torque *= torqueStep;
this.torque = torque;
if (Input.IsKeyPressed(Key.T) && !stabilizeDebounce) if (Input.IsKeyPressed(Key.T) && !stabilizeDebounce)
{ {
@ -91,13 +94,13 @@ public partial class TestThruster : RigidBody3D
public override void _PhysicsProcess(double delta) public override void _PhysicsProcess(double delta)
{ {
var thrust = Throttle * 100.0f; var thrust = Throttle * 100.0f;
var thrustVec = this.Transform * new Vector3(0.0f, thrust, 0f); var thrustVec = this.Transform.Basis * new Vector3(0.0f, thrust, 0f);
this.ApplyCentralForce(thrustVec); this.ApplyCentralForce(thrustVec);
Vector3 torque; Vector3 torque;
if (!this.torque.IsZeroApprox()) if (!this.torque.IsZeroApprox())
{ {
torque = this.torque; torque = this.Transform.Basis * this.torque;
} }
else if (stabilize) else if (stabilize)
{ {