Shuttle fixes (#16774)
This commit is contained in:
@@ -331,7 +331,7 @@ namespace Content.Server.Physics.Controllers
|
|||||||
if (body.LinearVelocity.Length > 0f)
|
if (body.LinearVelocity.Length > 0f)
|
||||||
{
|
{
|
||||||
// Minimum brake velocity for a direction to show its thrust appearance.
|
// Minimum brake velocity for a direction to show its thrust appearance.
|
||||||
var appearanceThreshold = 0.1f;
|
const float appearanceThreshold = 0.1f;
|
||||||
|
|
||||||
// Get velocity relative to the shuttle so we know which thrusters to fire
|
// Get velocity relative to the shuttle so we know which thrusters to fire
|
||||||
var shuttleVelocity = (-shuttleNorthAngle).RotateVec(body.LinearVelocity);
|
var shuttleVelocity = (-shuttleNorthAngle).RotateVec(body.LinearVelocity);
|
||||||
@@ -380,15 +380,15 @@ namespace Content.Server.Physics.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
var impulse = force * brakeInput * ShuttleComponent.BrakeCoefficient;
|
var impulse = force * brakeInput * ShuttleComponent.BrakeCoefficient;
|
||||||
var maxImpulse = shuttleVelocity * body.Mass;
|
impulse = shuttleNorthAngle.RotateVec(impulse);
|
||||||
|
var forceMul = frameTime * body.InvMass;
|
||||||
|
var maxVelocity = (-body.LinearVelocity).Length / forceMul;
|
||||||
|
|
||||||
if ((impulse * frameTime).LengthSquared > maxImpulse.LengthSquared)
|
// Don't overshoot
|
||||||
{
|
if (impulse.Length > maxVelocity)
|
||||||
impulse = -maxImpulse;
|
impulse = impulse.Normalized * maxVelocity;
|
||||||
}
|
|
||||||
|
|
||||||
PhysicsSystem.ApplyForce(shuttle.Owner, shuttleNorthAngle.RotateVec(impulse), body: body);
|
|
||||||
|
|
||||||
|
PhysicsSystem.ApplyForce(shuttle.Owner, impulse, body: body);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -397,17 +397,24 @@ namespace Content.Server.Physics.Controllers
|
|||||||
|
|
||||||
if (body.AngularVelocity != 0f)
|
if (body.AngularVelocity != 0f)
|
||||||
{
|
{
|
||||||
var impulse = shuttle.AngularThrust * brakeInput * (body.AngularVelocity > 0f ? -1f : 1f) * ShuttleComponent.BrakeCoefficient;
|
var torque = shuttle.AngularThrust * brakeInput * (body.AngularVelocity > 0f ? -1f : 1f) * ShuttleComponent.BrakeCoefficient;
|
||||||
var maxImpulse = body.AngularVelocity * body.Inertia;
|
var torqueMul = body.InvI * frameTime;
|
||||||
|
|
||||||
if (Math.Abs(impulse * frameTime) > Math.Abs(maxImpulse))
|
if (body.AngularVelocity > 0f)
|
||||||
{
|
{
|
||||||
impulse = -maxImpulse;
|
torque = MathF.Max(-body.AngularVelocity / torqueMul, torque);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
torque = MathF.Max(body.AngularVelocity / torqueMul, torque);
|
||||||
}
|
}
|
||||||
|
|
||||||
PhysicsSystem.ApplyTorque(shuttle.Owner, impulse, body: body);
|
if (!torque.Equals(0f))
|
||||||
|
{
|
||||||
|
PhysicsSystem.ApplyTorque(shuttle.Owner, torque, body: body);
|
||||||
_thruster.SetAngularThrust(shuttle, true);
|
_thruster.SetAngularThrust(shuttle, true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_thruster.SetAngularThrust(shuttle, false);
|
_thruster.SetAngularThrust(shuttle, false);
|
||||||
@@ -479,8 +486,15 @@ namespace Content.Server.Physics.Controllers
|
|||||||
|
|
||||||
totalForce = shuttleNorthAngle.RotateVec(totalForce);
|
totalForce = shuttleNorthAngle.RotateVec(totalForce);
|
||||||
|
|
||||||
if ((body.LinearVelocity + totalForce / body.Mass * frameTime).Length <= ShuttleComponent.MaxLinearVelocity)
|
var forceMul = frameTime * body.InvMass;
|
||||||
|
var maxVelocity = (ShuttleComponent.MaxLinearVelocity - body.LinearVelocity.Length) / forceMul;
|
||||||
|
|
||||||
|
if (maxVelocity != 0f)
|
||||||
{
|
{
|
||||||
|
// Don't overshoot
|
||||||
|
if (totalForce.Length > maxVelocity)
|
||||||
|
totalForce = totalForce.Normalized * maxVelocity;
|
||||||
|
|
||||||
PhysicsSystem.ApplyForce(shuttle.Owner, totalForce, body: body);
|
PhysicsSystem.ApplyForce(shuttle.Owner, totalForce, body: body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -495,20 +509,24 @@ namespace Content.Server.Physics.Controllers
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
PhysicsSystem.SetSleepingAllowed(shuttle.Owner, body, false);
|
PhysicsSystem.SetSleepingAllowed(shuttle.Owner, body, false);
|
||||||
var impulse = shuttle.AngularThrust * -angularInput;
|
var torque = shuttle.AngularThrust * -angularInput;
|
||||||
var tickChange = impulse * frameTime * body.InvI;
|
|
||||||
|
|
||||||
// If the rotation brings it above speedcap then noop.
|
// Need to cap the velocity if 1 tick of input brings us over cap so we don't continuously
|
||||||
if (Math.Sign(body.AngularVelocity) != Math.Sign(tickChange) ||
|
// edge onto the cap over and over.
|
||||||
Math.Abs(body.AngularVelocity + tickChange) <= ShuttleComponent.MaxAngularVelocity)
|
var torqueMul = body.InvI * frameTime;
|
||||||
|
|
||||||
|
torque = Math.Clamp(torque,
|
||||||
|
(-ShuttleComponent.MaxAngularVelocity - body.AngularVelocity) / torqueMul,
|
||||||
|
(ShuttleComponent.MaxAngularVelocity - body.AngularVelocity) / torqueMul);
|
||||||
|
|
||||||
|
if (!torque.Equals(0f))
|
||||||
{
|
{
|
||||||
PhysicsSystem.ApplyTorque(shuttle.Owner, impulse, body: body);
|
PhysicsSystem.ApplyTorque(shuttle.Owner, torque, body: body);
|
||||||
}
|
|
||||||
|
|
||||||
_thruster.SetAngularThrust(shuttle, true);
|
_thruster.SetAngularThrust(shuttle, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private bool CanPilot(ShuttleComponent shuttle)
|
private bool CanPilot(ShuttleComponent shuttle)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,9 +14,9 @@ namespace Content.Server.Shuttles.Components
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public const float BrakeCoefficient = 1.5f;
|
public const float BrakeCoefficient = 1.5f;
|
||||||
|
|
||||||
public const float MaxLinearVelocity = 10f;
|
public const float MaxLinearVelocity = 20f;
|
||||||
|
|
||||||
public const float MaxAngularVelocity = 1f;
|
public const float MaxAngularVelocity = 4f;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The cached thrust available for each cardinal direction
|
/// The cached thrust available for each cardinal direction
|
||||||
|
|||||||
@@ -161,4 +161,3 @@
|
|||||||
map: ["enum.ThrusterVisualLayers.ThrustingUnshaded"]
|
map: ["enum.ThrusterVisualLayers.ThrustingUnshaded"]
|
||||||
shader: unshaded
|
shader: unshaded
|
||||||
visible: false
|
visible: false
|
||||||
offset: 0, 1
|
|
||||||
|
|||||||
Reference in New Issue
Block a user