42 lines
825 B
C#
42 lines
825 B
C#
using Sandbox;
|
|
using System;
|
|
|
|
namespace VeloX;
|
|
|
|
public abstract partial class VeloXBase
|
|
{
|
|
|
|
private Vector3 angForce;
|
|
|
|
private void PhysicsSimulate()
|
|
{
|
|
var drag = AngularDrag;
|
|
var mass = Body.Mass;
|
|
var angVel = Body.AngularVelocity;
|
|
|
|
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 )
|
|
foreach ( var v in Wheels )
|
|
if ( v.AutoPhysics ) v.DoPhysics( this );
|
|
|
|
var totalSpeed = TotalSpeed + Math.Abs( Body.AngularVelocity.z );
|
|
|
|
var factor = 1 - Math.Clamp( totalSpeed / 30, 0, 1 );
|
|
|
|
if ( factor > 0.1f )
|
|
{
|
|
var vel = Body.Velocity;
|
|
|
|
var rt = WorldRotation.Right;
|
|
|
|
var force = rt.Dot( vel ) / Time.Delta * mass * factor * rt;
|
|
Body.ApplyForce( -force );
|
|
}
|
|
|
|
Body.ApplyTorque( angForce );
|
|
}
|
|
}
|