59 lines
1.2 KiB
C#
59 lines
1.2 KiB
C#
using Sandbox;
|
|
|
|
namespace VeloX;
|
|
|
|
public abstract partial class VeloXBase
|
|
{
|
|
|
|
private Vector3 linForce;
|
|
private Vector3 angForce;
|
|
[Property] float BrakeForce { get; set; } = 1500f;
|
|
[Property] float HandbrakeForce { get; set; } = 3500f;
|
|
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.BrakeTorque = SwappedBrakes * BrakeForce;
|
|
if ( !v.IsFront )
|
|
v.BrakeTorque += Handbrake * HandbrakeForce;
|
|
|
|
v.Update( this, in dt );
|
|
v.DoPhysics( in dt );
|
|
}
|
|
|
|
|
|
|
|
Body.Velocity = vehVel;
|
|
Body.AngularVelocity = vehAngVel;
|
|
}
|
|
|
|
Body.ApplyForce( linForce );
|
|
Body.ApplyTorque( angForce );
|
|
|
|
|
|
}
|
|
}
|