new maps and other improvements
This commit is contained in:
parent
b02f14ee47
commit
68626640c2
@ -45,7 +45,7 @@ public partial class VeloXWheel
|
|||||||
_skidMark.CastShadows = false;
|
_skidMark.CastShadows = false;
|
||||||
_skidMark.Width = Width.MeterToInch() / 2;
|
_skidMark.Width = Width.MeterToInch() / 2;
|
||||||
_skidMark.AutoCalculateNormals = false;
|
_skidMark.AutoCalculateNormals = false;
|
||||||
_skidMark.SplineInterpolation = 4;
|
_skidMark.SplineInterpolation = 1;
|
||||||
go.Flags = go.Flags.WithFlag( GameObjectFlags.Hidden, true );
|
go.Flags = go.Flags.WithFlag( GameObjectFlags.Hidden, true );
|
||||||
go.Flags = go.Flags.WithFlag( GameObjectFlags.NotNetworked, true );
|
go.Flags = go.Flags.WithFlag( GameObjectFlags.NotNetworked, true );
|
||||||
SkidMarks.Enqueue( _skidMark );
|
SkidMarks.Enqueue( _skidMark );
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using Sandbox;
|
using Sandbox;
|
||||||
|
using Sandbox.Utility;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace VeloX;
|
namespace VeloX;
|
||||||
@ -80,6 +81,7 @@ public partial class VeloXWheel : Component
|
|||||||
public void UpdateForce()
|
public void UpdateForce()
|
||||||
{
|
{
|
||||||
Vehicle.Body.ApplyForceAt( ContactPosition, FrictionForce + ContactNormal * Fz.MeterToInch() );
|
Vehicle.Body.ApplyForceAt( ContactPosition, FrictionForce + ContactNormal * Fz.MeterToInch() );
|
||||||
|
FrictionForce = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void StepPhys( VeloXBase vehicle, in float dt )
|
internal void StepPhys( VeloXBase vehicle, in float dt )
|
||||||
@ -110,7 +112,6 @@ public partial class VeloXWheel : Component
|
|||||||
Compression = wheelTraceData.Compression / hitCount;
|
Compression = wheelTraceData.Compression / hitCount;
|
||||||
ContactNormal = (wheelTraceData.ContactNormal / hitCount).Normal;
|
ContactNormal = (wheelTraceData.ContactNormal / hitCount).Normal;
|
||||||
ContactPosition = wheelTraceData.ContactPosition / hitCount;
|
ContactPosition = wheelTraceData.ContactPosition / hitCount;
|
||||||
//DoSuspensionSounds( vehicle, (RestLength - Compression) * 0.8f);
|
|
||||||
LastLength = RestLength - Compression;
|
LastLength = RestLength - Compression;
|
||||||
|
|
||||||
UpdateHitVariables();
|
UpdateHitVariables();
|
||||||
@ -119,11 +120,14 @@ public partial class VeloXWheel : Component
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
IsOnGround = false;
|
IsOnGround = false;
|
||||||
// Wheel is off the ground
|
|
||||||
Compression = 0f;
|
Compression = 0f;
|
||||||
Fz = 0f;
|
Fz = 0f;
|
||||||
ContactNormal = Vector3.Up;
|
ContactNormal = Vector3.Up;
|
||||||
ContactPosition = WorldPosition;
|
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 )
|
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
|
if ( trace.StartedSolid )
|
||||||
.FromTo( start, end )
|
{
|
||||||
.Cylinder( width, Radius.MeterToInch() )
|
trace = Scene.Trace
|
||||||
.Rotated( vehicle.WorldRotation * CylinderOffset )
|
.FromTo( start, end + Vehicle.WorldRotation.Down * Radius.MeterToInch() )
|
||||||
.UseHitPosition( false )
|
.UseHitPosition( false )
|
||||||
.IgnoreGameObjectHierarchy( Vehicle.GameObject )
|
.IgnoreGameObjectHierarchy( Vehicle.GameObject )
|
||||||
.WithCollisionRules( Vehicle.GameObject.Tags )
|
.WithCollisionRules( Vehicle.GameObject.Tags )
|
||||||
.Run();
|
.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 );
|
//DebugOverlay.Trace( trace, overlay: true );
|
||||||
if ( trace.Hit )
|
if ( trace.Hit )
|
||||||
|
|||||||
@ -1,6 +1,4 @@
|
|||||||
using Sandbox;
|
using Sandbox;
|
||||||
using System;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
namespace VeloX;
|
namespace VeloX;
|
||||||
|
|
||||||
@ -26,11 +24,13 @@ internal sealed class WheelManager : GameObjectSystem
|
|||||||
var timeDelta = Time.Delta;
|
var timeDelta = Time.Delta;
|
||||||
Sandbox.Utility.Parallel.ForEach( wheels, item =>
|
Sandbox.Utility.Parallel.ForEach( wheels, item =>
|
||||||
{
|
{
|
||||||
if ( !item.IsProxy )
|
if ( !item.IsProxy && item.IsValid() )
|
||||||
item.DoPhysics( timeDelta );
|
item.DoPhysics( timeDelta );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
foreach ( var wheel in wheels )
|
foreach ( var wheel in wheels )
|
||||||
wheel.UpdateForce();
|
if ( !wheel.IsProxy && wheel.IsValid() )
|
||||||
|
wheel.UpdateForce();
|
||||||
|
|
||||||
//sw.Stop();
|
//sw.Stop();
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ internal sealed class WheelManager : GameObjectSystem
|
|||||||
var timeDelta = Time.Delta;
|
var timeDelta = Time.Delta;
|
||||||
Sandbox.Utility.Parallel.ForEach( engines, item =>
|
Sandbox.Utility.Parallel.ForEach( engines, item =>
|
||||||
{
|
{
|
||||||
if ( !item.IsProxy )
|
if ( !item.IsProxy && item.IsValid() )
|
||||||
item.UpdateEngine( timeDelta );
|
item.UpdateEngine( timeDelta );
|
||||||
} );
|
} );
|
||||||
//sw.Stop();
|
//sw.Stop();
|
||||||
|
|||||||
@ -40,7 +40,7 @@ public partial class VeloXCar
|
|||||||
_sideArea = Dimensions.y * Dimensions.z * 0.8f;
|
_sideArea = Dimensions.y * Dimensions.z * 0.8f;
|
||||||
_forwardSpeed = LocalVelocity.x.InchToMeter();
|
_forwardSpeed = LocalVelocity.x.InchToMeter();
|
||||||
_sideSpeed = LocalVelocity.y.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);
|
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 );
|
var force = new Vector3( longitudinalDragForce.MeterToInch(), lateralDragForce.MeterToInch(), 0 ).RotateAround( Vector3.Zero, WorldRotation );
|
||||||
Body.ApplyForce( force );
|
Body.ApplyForce( force );
|
||||||
|
|||||||
@ -38,11 +38,21 @@ public partial class VeloXCar : VeloXBase
|
|||||||
if ( Math.Abs( inputSteer ) < 0.1f )
|
if ( Math.Abs( inputSteer ) < 0.1f )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ( Math.Abs( WorldRotation.Angles().roll ) < 70 )
|
if ( IsOnGround && Math.Abs( WorldRotation.Roll() ) < 60 )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var angVel = Body.AngularVelocity;
|
var angVel = Body.WorldTransform.PointToLocal( WorldPosition + Body.AngularVelocity );
|
||||||
var force = inputSteer * Mass * Math.Clamp( 1 - angVel.x / 50, 0, 1 ) * 0.05f;
|
|
||||||
|
|
||||||
|
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;
|
Body.AngularVelocity -= Body.WorldRotation.Forward * force * dt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user