|
@@ -10,6 +10,7 @@ public class WanderingAI : MonoBehaviour
|
|
public Transform[] waypoints;
|
|
public Transform[] waypoints;
|
|
public List<Transform> waypointsList;
|
|
public List<Transform> waypointsList;
|
|
public float[] wanderTimer;
|
|
public float[] wanderTimer;
|
|
|
|
+ public List<float>[] waitingTimer;
|
|
[Header("Scattering around the target")]
|
|
[Header("Scattering around the target")]
|
|
public float targetScattering = 5.0f; //Streuung
|
|
public float targetScattering = 5.0f; //Streuung
|
|
[Header("Leave Settings")]
|
|
[Header("Leave Settings")]
|
|
@@ -40,6 +41,7 @@ public class WanderingAI : MonoBehaviour
|
|
humansNMA = gameObject.GetComponent<InstantiatePrefab>().humanNavMeshAgent;
|
|
humansNMA = gameObject.GetComponent<InstantiatePrefab>().humanNavMeshAgent;
|
|
humansA = gameObject.GetComponent<InstantiatePrefab>().humanAnimator;
|
|
humansA = gameObject.GetComponent<InstantiatePrefab>().humanAnimator;
|
|
wanderTimer = gameObject.GetComponent<InstantiatePrefab>().wanderTimer;
|
|
wanderTimer = gameObject.GetComponent<InstantiatePrefab>().wanderTimer;
|
|
|
|
+ waitingTimer = gameObject.GetComponent<InstantiatePrefab>().waitingTimer;
|
|
waypoints = gameObject.GetComponent<InstantiatePrefab>().waypointsArray;
|
|
waypoints = gameObject.GetComponent<InstantiatePrefab>().waypointsArray;
|
|
waypointsList = new List<Transform>(waypoints);
|
|
waypointsList = new List<Transform>(waypoints);
|
|
humansPrio = gameObject.GetComponent<InstantiatePrefab>().humanPriorities;
|
|
humansPrio = gameObject.GetComponent<InstantiatePrefab>().humanPriorities;
|
|
@@ -61,41 +63,83 @@ public class WanderingAI : MonoBehaviour
|
|
globalTimer = 0;
|
|
globalTimer = 0;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ //private void FixedUpdate()
|
|
|
|
+ //{
|
|
|
|
+ // for(int i = 0; i < humansGO.Length; ++i)
|
|
|
|
+ // {
|
|
|
|
+ // if (timer[i] >= wanderTimer[i])
|
|
|
|
+ // {
|
|
|
|
+ // if (waypoints.Length == 0) return;
|
|
|
|
+
|
|
|
|
+ // int currentWP = Random.Range(0, waypointsList.Count);
|
|
|
|
+ // target[i][0] = CheckTarget(waypointsList[currentWP].transform.position, targetScattering);
|
|
|
|
+
|
|
|
|
+ // if(target[i][0].x != float.PositiveInfinity)
|
|
|
|
+ // {
|
|
|
|
+ // for (int j = 0; j < humansGO[i].Length; ++j)
|
|
|
|
+ // {
|
|
|
|
+ // target[i][j] = target[i][0];
|
|
|
|
+
|
|
|
|
+ // if (humansNMA[i][j].isActiveAndEnabled)
|
|
|
|
+ // humansNMA[i][j].SetDestination(target[i][j]);
|
|
|
|
+
|
|
|
|
+ // humansA[i][j].SetBool(isWalking, humansNMA[i][j].velocity.magnitude > 0.01f);
|
|
|
|
+ // }
|
|
|
|
+ // timer[i] = 0;
|
|
|
|
+ // // remove from list to ensure that all WP are visited at the frequency indicated; if list empty fill list with initial WPs
|
|
|
|
+ // ReduceWaypoints(currentWP);
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ // else
|
|
|
|
+ // {
|
|
|
|
+ // for (int j = 0; j < humansGO[i].Length; ++j)
|
|
|
|
+ // {
|
|
|
|
+ // humansA[i][j].SetBool(isWalking, humansNMA[i][j].velocity.magnitude > 0.01f);
|
|
|
|
+
|
|
|
|
+ // // if humans are not walking, then set priority to 0 so that the other humans dont disturb them
|
|
|
|
+ // if(humansNMA[i][j].velocity.magnitude <= 0.01f)
|
|
|
|
+ // humansNMA[i][j].avoidancePriority = 0;
|
|
|
|
+ // else
|
|
|
|
+ // humansNMA[i][j].avoidancePriority = humansPrio[i][j];
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ // timer[i] += Time.deltaTime;
|
|
|
|
+ // }
|
|
|
|
+ //}
|
|
|
|
+
|
|
private void FixedUpdate()
|
|
private void FixedUpdate()
|
|
{
|
|
{
|
|
- for(int i = 0; i < humansGO.Length; ++i)
|
|
|
|
|
|
+ for (int i = 0; i < humansGO.Length; ++i)
|
|
{
|
|
{
|
|
- if (timer[i] >= wanderTimer[i])
|
|
|
|
- {
|
|
|
|
- if (waypoints.Length == 0) return;
|
|
|
|
|
|
+ if (waypoints.Length == 0) return;
|
|
|
|
|
|
- int currentWP = Random.Range(0, waypointsList.Count);
|
|
|
|
- target[i][0] = checkTarget(waypointsList[currentWP].transform.position, targetScattering);
|
|
|
|
-
|
|
|
|
- if(target[i][0].x != float.PositiveInfinity)
|
|
|
|
|
|
+ for(int j = 0; j < humansGO[i].Length; ++j)
|
|
|
|
+ {
|
|
|
|
+ if(target[i][j] == Vector3.zero ||
|
|
|
|
+ humansNMA[i][j].velocity.magnitude <= 0.01f ||
|
|
|
|
+ humansNMA[i][j].remainingDistance <= humansNMA[i][j].stoppingDistance ||
|
|
|
|
+ humansNMA[i][j].pathStatus == NavMeshPathStatus.PathComplete ||
|
|
|
|
+ !humansNMA[i][j].hasPath)
|
|
{
|
|
{
|
|
- for (int j = 0; j < humansGO[i].Length; ++j)
|
|
|
|
|
|
+ int currentWP = Random.Range(0, waypointsList.Count);
|
|
|
|
+ target[i][j] = CheckTarget(waypointsList[currentWP].transform.position, targetScattering);
|
|
|
|
+
|
|
|
|
+ if (target[i][0].x != float.PositiveInfinity)
|
|
{
|
|
{
|
|
- target[i][j] = target[i][0];
|
|
|
|
-
|
|
|
|
if (humansNMA[i][j].isActiveAndEnabled)
|
|
if (humansNMA[i][j].isActiveAndEnabled)
|
|
humansNMA[i][j].SetDestination(target[i][j]);
|
|
humansNMA[i][j].SetDestination(target[i][j]);
|
|
|
|
|
|
humansA[i][j].SetBool(isWalking, humansNMA[i][j].velocity.magnitude > 0.01f);
|
|
humansA[i][j].SetBool(isWalking, humansNMA[i][j].velocity.magnitude > 0.01f);
|
|
|
|
+
|
|
}
|
|
}
|
|
- timer[i] = 0;
|
|
|
|
// remove from list to ensure that all WP are visited at the frequency indicated; if list empty fill list with initial WPs
|
|
// remove from list to ensure that all WP are visited at the frequency indicated; if list empty fill list with initial WPs
|
|
- reduceWaypoints(currentWP);
|
|
|
|
|
|
+ ReduceWaypoints(currentWP);
|
|
}
|
|
}
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- for (int j = 0; j < humansGO[i].Length; ++j)
|
|
|
|
|
|
+ else
|
|
{
|
|
{
|
|
humansA[i][j].SetBool(isWalking, humansNMA[i][j].velocity.magnitude > 0.01f);
|
|
humansA[i][j].SetBool(isWalking, humansNMA[i][j].velocity.magnitude > 0.01f);
|
|
-
|
|
|
|
// if humans are not walking, then set priority to 0 so that the other humans dont disturb them
|
|
// if humans are not walking, then set priority to 0 so that the other humans dont disturb them
|
|
- if(humansNMA[i][j].velocity.magnitude <= 0.01f)
|
|
|
|
|
|
+ if (humansNMA[i][j].velocity.magnitude <= 0.01f)
|
|
humansNMA[i][j].avoidancePriority = 0;
|
|
humansNMA[i][j].avoidancePriority = 0;
|
|
else
|
|
else
|
|
humansNMA[i][j].avoidancePriority = humansPrio[i][j];
|
|
humansNMA[i][j].avoidancePriority = humansPrio[i][j];
|
|
@@ -103,9 +147,10 @@ public class WanderingAI : MonoBehaviour
|
|
}
|
|
}
|
|
timer[i] += Time.deltaTime;
|
|
timer[i] += Time.deltaTime;
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
- public static Vector3 checkTarget(Vector3 target, float dist)
|
|
|
|
|
|
+ public static Vector3 CheckTarget(Vector3 target, float dist)
|
|
{
|
|
{
|
|
Vector3 modifiedTarget = Random.insideUnitSphere * dist + target;
|
|
Vector3 modifiedTarget = Random.insideUnitSphere * dist + target;
|
|
// SamplePosition also checks the y axis. However, this is not relevant for me, so valid positions (x & z) are also discarded.
|
|
// SamplePosition also checks the y axis. However, this is not relevant for me, so valid positions (x & z) are also discarded.
|
|
@@ -118,7 +163,7 @@ public class WanderingAI : MonoBehaviour
|
|
return navHit.position;
|
|
return navHit.position;
|
|
}
|
|
}
|
|
|
|
|
|
- public void reduceWaypoints(int index)
|
|
|
|
|
|
+ public void ReduceWaypoints(int index)
|
|
{
|
|
{
|
|
waypointsList.RemoveAt(index);
|
|
waypointsList.RemoveAt(index);
|
|
|
|
|
|
@@ -126,7 +171,7 @@ public class WanderingAI : MonoBehaviour
|
|
waypointsList = new List<Transform>(waypoints);
|
|
waypointsList = new List<Transform>(waypoints);
|
|
}
|
|
}
|
|
|
|
|
|
- public void leaveMarket(int i)
|
|
|
|
|
|
+ public void LeaveMarket(int i)
|
|
{
|
|
{
|
|
for (int j = 0; j < humansGO[i].Length; ++j)
|
|
for (int j = 0; j < humansGO[i].Length; ++j)
|
|
{
|
|
{
|