velox/Code/Base/VeloXBase.cs
2025-12-01 00:02:14 +07:00

66 lines
1.5 KiB
C#

using Sandbox;
using System;
namespace VeloX;
public abstract partial class VeloXBase : Component, IGameObjectNetworkEvents
{
[Sync, Change( nameof( OnEngineIgnitionChange ) )]
public bool EngineIgnition { get; set; }
private void OnEngineIgnitionChange( bool oldvalue, bool newvalue )
{
if ( newvalue )
Engine?.StartEngine();
else
Engine?.StopEngine();
}
[Property] public Vector3 AngularDrag { get; set; } = new( -0.1f, -0.1f, -3 );
[Property] public float Mass { get; set; } = 900;
[Property, Group( "Components" )] public Rigidbody Body { get; protected set; }
[Property, Group( "Components" )] public Collider Collider { get; protected set; }
[Sync( SyncFlags.Interpolate )] public Angles SteerAngle { get; set; }
[Sync( SyncFlags.Interpolate )] public Vector3 LocalVelocity { get; set; }
[Sync( SyncFlags.Interpolate )] public Vector3 Velocity { get; set; }
public float ForwardSpeed;
public float TotalSpeed;
protected override void OnFixedUpdate()
{
if ( !IsProxy )
{
LocalVelocity = WorldTransform.PointToLocal( WorldPosition + Body.Velocity );
Velocity = Body.Velocity;
}
ForwardSpeed = LocalVelocity.x;
TotalSpeed = LocalVelocity.Length;
if ( IsProxy )
return;
Body.PhysicsBody.Mass = Mass;
FixedUpdate();
}
protected virtual void FixedUpdate()
{
UpdateInput();
PhysicsSimulate();
}
//void IGameObjectNetworkEvents.NetworkOwnerChanged( Connection newOwner, Connection previousOwner )
//{
// Driver = newOwner;
// EngineIgnition = Driver is not null;
//}
}