new maps and other improvements

This commit is contained in:
Valera 2025-11-23 22:51:41 +07:00
parent b02f14ee47
commit 68626640c2
5 changed files with 58 additions and 20 deletions

View File

@ -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 );

View File

@ -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,8 +135,10 @@ public partial class VeloXWheel : Component
private bool TraceWheel( VeloXBase vehicle, ref WheelTraceData wheelTraceData, Vector3 start, Vector3 end, float width, in float dt )
{
var trace = Scene.Trace
SceneTraceResult trace;
if ( IsOnGround && vehicle.TotalSpeed < 550 )
{
trace = Scene.Trace
.FromTo( start, end )
.Cylinder( width, Radius.MeterToInch() )
.Rotated( vehicle.WorldRotation * CylinderOffset )
@ -141,6 +147,28 @@ public partial class VeloXWheel : Component
.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 )
{

View File

@ -1,6 +1,4 @@
using Sandbox;
using System;
using System.Diagnostics;
using System.Linq;
namespace VeloX;
@ -26,10 +24,12 @@ 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 )
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();

View File

@ -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 );

View File

@ -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;
}
}