velox/Code/Base/VeloXBase.Phys.cs
2025-11-06 12:13:30 +07:00

58 lines
1.1 KiB
C#

using Sandbox;
namespace VeloX;
public abstract partial class VeloXBase
{
private Vector3 linForce;
private Vector3 angForce;
private void PhysicsSimulate()
{
if ( Body.Sleeping && Input.AnalogMove.x == 0 )
return;
var drag = AngularDrag;
var mass = Body.Mass;
var angVel = Body.AngularVelocity;
linForce.x = 0;
linForce.y = 0;
linForce.z = 0;
angForce = angForce.WithX( angVel.x * drag.x * mass * 1000 );
angForce = angForce.WithY( angVel.y * drag.y * mass * 1000 );
angForce = angForce.WithZ( angVel.z * drag.z * mass * 1000 );
if ( Wheels.Count > 0 )
{
Vector3 vehVel = Body.Velocity;
Vector3 vehAngVel = Body.AngularVelocity;
var dt = Time.Delta;
CombinedLoad = 0;
foreach ( var v in Wheels )
CombinedLoad += v.Fz;
foreach ( var v in Wheels )
{
v.Brake = SwappedBrakes;
if ( !v.IsFront )
v.Brake += Handbrake;
v.Update( this, in dt );
v.DoPhysics( in dt );
}
Body.Velocity = vehVel;
Body.AngularVelocity = vehAngVel;
}
Body.ApplyForce( linForce );
Body.ApplyTorque( angForce );
}
}