velox/Code/Base/VeloXBase.Phys.cs
2025-06-11 20:19:35 +07:00

44 lines
830 B
C#

using Sandbox;
namespace VeloX;
public abstract partial class VeloXBase
{
private Vector3 linForce;
private Vector3 angForce;
private void PhysicsSimulate()
{
var drag = AngularDrag;
var mass = Body.Mass;
var angVel = Body.AngularVelocity;
linForce.x = 0;
linForce.y = 0;
linForce.z = 0;
angForce.x = angVel.x * drag.x * mass;
angForce.y = angVel.y * drag.y * mass;
angForce.z = angVel.z * drag.z * mass;
if ( Wheels.Count > 0 )
{
Vector3 vehVel = Body.Velocity;
Vector3 vehAngVel = Body.AngularVelocity;
var dt = Time.Delta;
foreach ( var v in Wheels )
v.DoPhysics( this, ref vehVel, ref vehAngVel, ref linForce, ref angForce, in dt );
Body.Velocity = vehVel;
Body.AngularVelocity = vehAngVel;
}
Body.ApplyForce( linForce );
Body.ApplyTorque( angForce );
}
}