50 lines
993 B
C#
50 lines
993 B
C#
using Sandbox;
|
|
using System;
|
|
|
|
namespace VeloX;
|
|
|
|
[Group( "VeloX" )]
|
|
[Title( "VeloX - Car" )]
|
|
public partial class VeloXCar : VeloXBase
|
|
{
|
|
protected override void OnFixedUpdate()
|
|
{
|
|
base.OnFixedUpdate();
|
|
|
|
if ( IsProxy )
|
|
return;
|
|
UpdateABS();
|
|
UpdateESC();
|
|
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 ( IsOnGround || Math.Abs( WorldRotation.Roll() ) < 60 )
|
|
return;
|
|
|
|
var angVel = Body.WorldTransform.PointToLocal( WorldPosition + Body.AngularVelocity );
|
|
|
|
|
|
float maxAngularVelocity = 2.0f;
|
|
|
|
float velocityFactor = 1.0f - Math.Clamp( Math.Abs( angVel.x ) / maxAngularVelocity, 0f, 1f );
|
|
|
|
if ( velocityFactor <= 0.01f )
|
|
return;
|
|
|
|
var force = inputSteer * velocityFactor * 150;
|
|
|
|
Body.AngularVelocity -= Body.WorldRotation.Forward * force * dt;
|
|
}
|
|
}
|