40 lines
756 B
C#
40 lines
756 B
C#
using Sandbox;
|
|
using System;
|
|
|
|
namespace VeloX;
|
|
|
|
[Group( "VeloX" )]
|
|
[Title( "VeloX - Car" )]
|
|
public partial class VeloXCar : VeloXBase
|
|
{
|
|
|
|
protected override void OnFixedUpdate()
|
|
{
|
|
if ( IsProxy )
|
|
return;
|
|
|
|
base.OnFixedUpdate();
|
|
|
|
var dt = Time.Delta;
|
|
//EngineThink( dt );
|
|
SimulateAerodinamics( dt );
|
|
//WheelThink( dt );
|
|
UpdateSteering( dt );
|
|
UpdateUnflip( dt );
|
|
UpdateDrift( dt );
|
|
}
|
|
|
|
private void UpdateUnflip( float dt )
|
|
{
|
|
if ( Math.Abs( inputSteer ) < 0.1f )
|
|
return;
|
|
|
|
if ( Math.Abs( WorldRotation.Angles().roll ) < 70 )
|
|
return;
|
|
|
|
var angVel = Body.AngularVelocity;
|
|
var force = inputSteer * Mass * Math.Clamp( 1 - angVel.x / 50, 0, 1 ) * 0.05f;
|
|
Body.AngularVelocity -= Body.WorldRotation.Forward * force * dt;
|
|
}
|
|
}
|