From 68626640c2117eced3da1684db1df20abf6f00ca Mon Sep 17 00:00:00 2001 From: Valera Date: Sun, 23 Nov 2025 22:51:41 +0700 Subject: [PATCH] new maps and other improvements --- Code/Base/Wheel/VeloXWheel.Skid.cs | 2 +- Code/Base/Wheel/VeloXWheel.cs | 48 +++++++++++++++++++++++------- Code/Base/Wheel/WheelManager.cs | 10 +++---- Code/Car/VeloXCar.Aerodinamics.cs | 2 +- Code/Car/VeloXCar.cs | 16 ++++++++-- 5 files changed, 58 insertions(+), 20 deletions(-) diff --git a/Code/Base/Wheel/VeloXWheel.Skid.cs b/Code/Base/Wheel/VeloXWheel.Skid.cs index f5d5277..17156d4 100644 --- a/Code/Base/Wheel/VeloXWheel.Skid.cs +++ b/Code/Base/Wheel/VeloXWheel.Skid.cs @@ -45,7 +45,7 @@ public partial class VeloXWheel _skidMark.CastShadows = false; _skidMark.Width = Width.MeterToInch() / 2; _skidMark.AutoCalculateNormals = false; - _skidMark.SplineInterpolation = 4; + _skidMark.SplineInterpolation = 1; go.Flags = go.Flags.WithFlag( GameObjectFlags.Hidden, true ); go.Flags = go.Flags.WithFlag( GameObjectFlags.NotNetworked, true ); SkidMarks.Enqueue( _skidMark ); diff --git a/Code/Base/Wheel/VeloXWheel.cs b/Code/Base/Wheel/VeloXWheel.cs index 6951df1..258d66c 100644 --- a/Code/Base/Wheel/VeloXWheel.cs +++ b/Code/Base/Wheel/VeloXWheel.cs @@ -1,4 +1,5 @@ using Sandbox; +using Sandbox.Utility; using System; namespace VeloX; @@ -80,6 +81,7 @@ public partial class VeloXWheel : Component public void UpdateForce() { Vehicle.Body.ApplyForceAt( ContactPosition, FrictionForce + ContactNormal * Fz.MeterToInch() ); + FrictionForce = 0; } internal void StepPhys( VeloXBase vehicle, in float dt ) @@ -110,7 +112,6 @@ public partial class VeloXWheel : Component Compression = wheelTraceData.Compression / hitCount; ContactNormal = (wheelTraceData.ContactNormal / hitCount).Normal; ContactPosition = wheelTraceData.ContactPosition / hitCount; - //DoSuspensionSounds( vehicle, (RestLength - Compression) * 0.8f); LastLength = RestLength - Compression; UpdateHitVariables(); @@ -119,11 +120,14 @@ public partial class VeloXWheel : Component else { IsOnGround = false; - // Wheel is off the ground Compression = 0f; Fz = 0f; ContactNormal = Vector3.Up; ContactPosition = WorldPosition; + LastLength = RestLength; + + UpdateHitVariables(); + UpdateFriction( dt ); } } @@ -131,15 +135,39 @@ public partial class VeloXWheel : Component private bool TraceWheel( VeloXBase vehicle, ref WheelTraceData wheelTraceData, Vector3 start, Vector3 end, float width, in float dt ) { + SceneTraceResult trace; + if ( IsOnGround && vehicle.TotalSpeed < 550 ) + { + trace = Scene.Trace + .FromTo( start, end ) + .Cylinder( width, Radius.MeterToInch() ) + .Rotated( vehicle.WorldRotation * CylinderOffset ) + .UseHitPosition( false ) + .IgnoreGameObjectHierarchy( Vehicle.GameObject ) + .WithCollisionRules( Vehicle.GameObject.Tags ) + .Run(); - var trace = Scene.Trace - .FromTo( start, end ) - .Cylinder( width, Radius.MeterToInch() ) - .Rotated( vehicle.WorldRotation * CylinderOffset ) - .UseHitPosition( false ) - .IgnoreGameObjectHierarchy( Vehicle.GameObject ) - .WithCollisionRules( Vehicle.GameObject.Tags ) - .Run(); + if ( trace.StartedSolid ) + { + trace = Scene.Trace + .FromTo( start, end + Vehicle.WorldRotation.Down * Radius.MeterToInch() ) + .UseHitPosition( false ) + .IgnoreGameObjectHierarchy( Vehicle.GameObject ) + .WithCollisionRules( Vehicle.GameObject.Tags ) + .Run(); + trace.EndPosition += Vehicle.WorldRotation.Up * Math.Min( Radius.MeterToInch(), trace.Distance ); + } + } + else + { + trace = Scene.Trace + .FromTo( start, end + Vehicle.WorldRotation.Down * Radius.MeterToInch() ) + .UseHitPosition( false ) + .IgnoreGameObjectHierarchy( Vehicle.GameObject ) + .WithCollisionRules( Vehicle.GameObject.Tags ) + .Run(); + trace.EndPosition += Vehicle.WorldRotation.Up * Math.Min( Radius.MeterToInch(), trace.Distance ); + } //DebugOverlay.Trace( trace, overlay: true ); if ( trace.Hit ) diff --git a/Code/Base/Wheel/WheelManager.cs b/Code/Base/Wheel/WheelManager.cs index 533c774..9d4e70a 100644 --- a/Code/Base/Wheel/WheelManager.cs +++ b/Code/Base/Wheel/WheelManager.cs @@ -1,6 +1,4 @@ using Sandbox; -using System; -using System.Diagnostics; using System.Linq; namespace VeloX; @@ -26,11 +24,13 @@ internal sealed class WheelManager : GameObjectSystem var timeDelta = Time.Delta; Sandbox.Utility.Parallel.ForEach( wheels, item => { - if ( !item.IsProxy ) + if ( !item.IsProxy && item.IsValid() ) item.DoPhysics( timeDelta ); } ); + foreach ( var wheel in wheels ) - wheel.UpdateForce(); + if ( !wheel.IsProxy && wheel.IsValid() ) + wheel.UpdateForce(); //sw.Stop(); @@ -48,7 +48,7 @@ internal sealed class WheelManager : GameObjectSystem var timeDelta = Time.Delta; Sandbox.Utility.Parallel.ForEach( engines, item => { - if ( !item.IsProxy ) + if ( !item.IsProxy && item.IsValid() ) item.UpdateEngine( timeDelta ); } ); //sw.Stop(); diff --git a/Code/Car/VeloXCar.Aerodinamics.cs b/Code/Car/VeloXCar.Aerodinamics.cs index 5c48243..0467dd4 100644 --- a/Code/Car/VeloXCar.Aerodinamics.cs +++ b/Code/Car/VeloXCar.Aerodinamics.cs @@ -40,7 +40,7 @@ public partial class VeloXCar _sideArea = Dimensions.y * Dimensions.z * 0.8f; _forwardSpeed = LocalVelocity.x.InchToMeter(); _sideSpeed = LocalVelocity.y.InchToMeter(); - longitudinalDragForce = 2 * RHO * _frontalArea * FrontalCd * (_forwardSpeed * _forwardSpeed) * (_forwardSpeed > 0 ? -1f : 1f); + longitudinalDragForce = 0.5f * RHO * _frontalArea * FrontalCd * (_forwardSpeed * _forwardSpeed) * (_forwardSpeed > 0 ? -1f : 1f); lateralDragForce = 0.5f * RHO * _sideArea * SideCd * (_sideSpeed * _sideSpeed) * (_sideSpeed > 0 ? -1f : 1f); var force = new Vector3( longitudinalDragForce.MeterToInch(), lateralDragForce.MeterToInch(), 0 ).RotateAround( Vector3.Zero, WorldRotation ); Body.ApplyForce( force ); diff --git a/Code/Car/VeloXCar.cs b/Code/Car/VeloXCar.cs index 212dd5d..4ea4f87 100644 --- a/Code/Car/VeloXCar.cs +++ b/Code/Car/VeloXCar.cs @@ -38,11 +38,21 @@ public partial class VeloXCar : VeloXBase if ( Math.Abs( inputSteer ) < 0.1f ) return; - if ( Math.Abs( WorldRotation.Angles().roll ) < 70 ) + if ( IsOnGround && Math.Abs( WorldRotation.Roll() ) < 60 ) return; - var angVel = Body.AngularVelocity; - var force = inputSteer * Mass * Math.Clamp( 1 - angVel.x / 50, 0, 1 ) * 0.05f; + 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; } }