mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-14 00:07:15 +00:00
...
This commit is contained in:
parent
61af25fc72
commit
ae537b455f
1 changed files with 7 additions and 6 deletions
|
@ -107,16 +107,17 @@ namespace SanAndreasUnity.Utilities
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float currentTime = Time.time;
|
||||||
Vector3 myPosition = agent.transform.position;
|
Vector3 myPosition = agent.transform.position;
|
||||||
|
|
||||||
agent.nextPosition = myPosition;
|
agent.nextPosition = myPosition;
|
||||||
|
|
||||||
Vector3 retreivedNextPosition = agent.nextPosition;
|
Vector3 retreivedNextPosition = agent.nextPosition;
|
||||||
|
|
||||||
if (Time.time - m_lastTimeWhenWarped > 1f
|
if (currentTime - m_lastTimeWhenWarped > 1f
|
||||||
&& (retreivedNextPosition.WithXAndZ() != myPosition.WithXAndZ() || !agent.isOnNavMesh))
|
&& (retreivedNextPosition.WithXAndZ() != myPosition.WithXAndZ() || !agent.isOnNavMesh))
|
||||||
{
|
{
|
||||||
m_lastTimeWhenWarped = Time.time;
|
m_lastTimeWhenWarped = currentTime;
|
||||||
|
|
||||||
bool bWarp = false;
|
bool bWarp = false;
|
||||||
bool bSetDestination = false;
|
bool bSetDestination = false;
|
||||||
|
@ -144,11 +145,11 @@ namespace SanAndreasUnity.Utilities
|
||||||
if (!agent.isOnNavMesh)
|
if (!agent.isOnNavMesh)
|
||||||
{
|
{
|
||||||
m_isMovingOffNavMesh = true; // immediately start moving when agent goes off the nav mesh
|
m_isMovingOffNavMesh = true; // immediately start moving when agent goes off the nav mesh
|
||||||
if (Time.time - m_timeWhenSampledOffNavMesh > 2.5f)
|
if (currentTime - m_timeWhenSampledOffNavMesh > 2.5f)
|
||||||
{
|
{
|
||||||
// try to sample position on nav mesh where agent could go
|
// try to sample position on nav mesh where agent could go
|
||||||
|
|
||||||
m_timeWhenSampledOffNavMesh = Time.time;
|
m_timeWhenSampledOffNavMesh = currentTime;
|
||||||
m_sampledPosOffNavMesh = null;
|
m_sampledPosOffNavMesh = null;
|
||||||
|
|
||||||
if (NavMesh.SamplePosition(myPosition, out var hit, 150f, agent.areaMask))
|
if (NavMesh.SamplePosition(myPosition, out var hit, 150f, agent.areaMask))
|
||||||
|
@ -171,7 +172,7 @@ namespace SanAndreasUnity.Utilities
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Time.time - m_lastTimeWhenSearchedForPath < 0.4f)
|
if (currentTime - m_lastTimeWhenSearchedForPath < 0.4f)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (agent.pathPending)
|
if (agent.pathPending)
|
||||||
|
@ -220,7 +221,7 @@ namespace SanAndreasUnity.Utilities
|
||||||
// from 5 to 12, with sqrt function, 150 as max distance
|
// from 5 to 12, with sqrt function, 150 as max distance
|
||||||
float regularUpdateInterval = 5 + 7 * Mathf.Clamp01(Mathf.Sqrt(Mathf.Min(distanceToTarget, 150f) / 150f));
|
float regularUpdateInterval = 5 + 7 * Mathf.Clamp01(Mathf.Sqrt(Mathf.Min(distanceToTarget, 150f) / 150f));
|
||||||
|
|
||||||
if (Time.time - m_lastTimeWhenSearchedForPath > regularUpdateInterval
|
if (currentTime - m_lastTimeWhenSearchedForPath > regularUpdateInterval
|
||||||
&& this.Destination.Value != m_lastAssignedDestination.Value)
|
&& this.Destination.Value != m_lastAssignedDestination.Value)
|
||||||
{
|
{
|
||||||
this.SetDestination();
|
this.SetDestination();
|
||||||
|
|
Loading…
Reference in a new issue