Compare commits
1 Commits
master
...
dynamic_li
| Author | SHA1 | Date | |
|---|---|---|---|
| 54ac069797 |
@@ -8,6 +8,7 @@ using FlaxEngine;
|
||||
using FlaxEngine.Assertions;
|
||||
using FlaxEngine.Networking;
|
||||
using Console = Game.Console;
|
||||
using System.Buffers;
|
||||
|
||||
namespace Game;
|
||||
|
||||
@@ -83,7 +84,7 @@ public struct PlayerMovementState
|
||||
|
||||
public struct TraceInfo
|
||||
{
|
||||
public RayCastHit[] hitInfos;
|
||||
public List<RayCastHit> hitInfos;
|
||||
public bool startSolid;
|
||||
|
||||
// closest hit
|
||||
@@ -141,6 +142,8 @@ public class PlayerMovement : Script
|
||||
|
||||
public uint PlayerId => playerActor ? playerActor.PlayerId : 0;
|
||||
|
||||
public LayersMask maskTest;
|
||||
|
||||
[ReadOnly]
|
||||
public float CurrentVelocity
|
||||
{
|
||||
@@ -757,15 +760,17 @@ public class PlayerMovement : Script
|
||||
//viewAnglesLastFrame = angles;
|
||||
}
|
||||
|
||||
private static bool SweepPlayerCollider(PlayerActor actor, Float3 start, Vector3 end, out RayCastHit[] hits)
|
||||
private static List<RayCastHit> _cachedHits = new();
|
||||
private static bool SweepPlayerCollider(PlayerActor actor, Float3 start, Vector3 end, out List<RayCastHit> hits)
|
||||
{
|
||||
Vector3 delta = end - start;
|
||||
float distance = delta.Length;
|
||||
Vector3 direction = delta.Normalized;
|
||||
|
||||
//_cachedHits.Clear();
|
||||
if (distance < 0.00000001f)
|
||||
{
|
||||
hits = new RayCastHit[0];//Array.Empty<RayCastHit>();
|
||||
hits = _cachedHits;//Array.Empty<RayCastHit>();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -773,7 +778,7 @@ public class PlayerMovement : Script
|
||||
CapsuleCollider capsuleCollider = actor.capsuleCollider;
|
||||
BoxCollider boxCollider = actor.boxCollider;
|
||||
MeshCollider meshCollider = actor.meshCollider;
|
||||
if (capsuleCollider && capsuleCollider.IsActive)
|
||||
/*if (capsuleCollider && capsuleCollider.IsActive)
|
||||
collided = Physics.CapsuleCastAll(start,
|
||||
capsuleCollider.Radius, capsuleCollider.Height,
|
||||
direction, out hits, capsuleCollider.Orientation, distance,
|
||||
@@ -785,16 +790,16 @@ public class PlayerMovement : Script
|
||||
direction, out hits, meshCollider.Orientation, distance,
|
||||
uint.MaxValue,
|
||||
false);
|
||||
else if (boxCollider && boxCollider.IsActive)
|
||||
else*/ if (boxCollider && boxCollider.IsActive)
|
||||
collided = Physics.BoxCastAll(start,
|
||||
boxCollider.OrientedBox.Extents,
|
||||
direction, out hits, boxCollider.Orientation, distance,
|
||||
direction, ref _cachedHits, boxCollider.Orientation, distance,
|
||||
uint.MaxValue,
|
||||
false);
|
||||
else
|
||||
throw new Exception("Player does not have a collider");
|
||||
|
||||
|
||||
hits = _cachedHits;
|
||||
|
||||
return collided;
|
||||
}
|
||||
@@ -857,6 +862,7 @@ public class PlayerMovement : Script
|
||||
return collided;
|
||||
}
|
||||
|
||||
private static List<RayCastHit> _cachedHitInfos = new List<RayCastHit>();
|
||||
/// <summary>
|
||||
/// Sweeps the player rigidbody in world and returns geometry which was hit during the trace.
|
||||
/// </summary>
|
||||
@@ -867,6 +873,7 @@ public class PlayerMovement : Script
|
||||
private static TraceInfo TracePlayer(PlayerActor actor, Vector3 start, Vector3 end)
|
||||
{
|
||||
TraceInfo traceInfo = new TraceInfo();
|
||||
traceInfo.hitInfos = _cachedHitInfos;
|
||||
|
||||
Vector3 delta = end - start;
|
||||
float maxDistance = delta.Length;
|
||||
@@ -921,7 +928,7 @@ public class PlayerMovement : Script
|
||||
if (hitInfo.Distance < closest.Distance)
|
||||
closest = hitInfo;
|
||||
|
||||
traceInfo.hitInfos = hitInfosFiltered.ToArray();
|
||||
traceInfo.hitInfos = hitInfosFiltered;
|
||||
|
||||
traceInfo.fraction = closest.Distance / maxDistance;
|
||||
traceInfo.hitNormal = closest.Normal;
|
||||
@@ -943,7 +950,7 @@ public class PlayerMovement : Script
|
||||
|
||||
if (!collided)
|
||||
{
|
||||
traceInfo.hitInfos = new RayCastHit[0];
|
||||
traceInfo.hitInfos = new List<RayCastHit>();
|
||||
traceInfo.fraction = 1f;
|
||||
traceInfo.endPosition = end;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user