new powertrain смерть чуркам
This commit is contained in:
45
Code/Base/Powertrain/Gearbox/BaseGearbox.cs
Normal file
45
Code/Base/Powertrain/Gearbox/BaseGearbox.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using Sandbox;
|
||||
using System;
|
||||
|
||||
namespace VeloX.Powertrain;
|
||||
|
||||
[Category( "VeloX/Powertrain/Gearbox" )]
|
||||
public abstract class BaseGearbox : PowertrainComponent
|
||||
{
|
||||
[Property] public override float Inertia { get; set; } = 0.01f;
|
||||
|
||||
protected float ratio;
|
||||
|
||||
public override float QueryInertia()
|
||||
{
|
||||
if ( !HasOutput || ratio == 0 )
|
||||
return Inertia;
|
||||
|
||||
return Inertia + Output.QueryInertia() / MathF.Pow( ratio, 2 );
|
||||
}
|
||||
|
||||
public override float QueryAngularVelocity( float angularVelocity )
|
||||
{
|
||||
this.angularVelocity = angularVelocity;
|
||||
if ( !HasOutput || ratio == 0 )
|
||||
return angularVelocity;
|
||||
|
||||
return Output.QueryAngularVelocity( angularVelocity ) * ratio;
|
||||
}
|
||||
|
||||
public override float ForwardStep( float torque, float inertia )
|
||||
{
|
||||
Torque = torque * ratio;
|
||||
|
||||
if ( !HasOutput )
|
||||
return torque;
|
||||
|
||||
if ( ratio == 0 )
|
||||
{
|
||||
Output.ForwardStep( 0, Inertia * 0.5f );
|
||||
return torque;
|
||||
}
|
||||
|
||||
return Output.ForwardStep( Torque, (inertia + Inertia) * MathF.Pow( ratio, 2 ) ) / ratio;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user