IEnumerator Spawn() { if (pedestrianCount > 100) { yield return(null); } while (true) { GameObject g = Instantiate(prefab, transform.position, Quaternion.identity, parent); PedestrianController pc = g.GetComponent <PedestrianController>(); pc.speed = 1 + Random.Range(0f, 0.25f); //give random color g.GetComponentInChildren <SkinnedMeshRenderer>().material.color = skintones[Random.Range(0, skintones.Length)]; pedestrianCount += 1; float rnd = Random.Range(0f, 1f); if (rnd > 0.5f) { g.GetComponent <PathAI>().node = waypoint.connections[0]; g.GetComponent <PathAI>().prevNode = waypoint; } else { g.GetComponent <PathAI>().node = waypoint.connections[1]; g.GetComponent <PathAI>().prevNode = waypoint; } yield return(new WaitForSeconds(5)); } }
public void GrabPedestrian(PedestrianController pedestrianRef) { if (!PedestrianQueue.Contains(pedestrianRef)) { if (bDropEnumRunning) { PedestrianRefs.Insert(0, pedestrianRef); } else { PedestrianQueue.Add(pedestrianRef); } if (!bGrabEnumRunning && !bDropEnumRunning) { startGrabEnum(pedestrianRef); } if (PedestrianRefs.Count > 0) { AnimationController.SetTrigger("PickupCarry"); } else { AnimationController.SetTrigger("PickupNoCarry"); } } }
private void Update() { if (pedestrianCrossing != null) { PedestrianCrossingController pedestrianCrossingController = pedestrianCrossing.GetComponent <PedestrianCrossingController>(); PedestrianController pedestrianController = pedestrian.GetComponent <PedestrianController>(); bool stopped = false; bool reversed = false; if (pedestrianCrossingController.carCounter > 0 || pedestrianCrossingController.dangerous) { stopped = true; if (pedestrianCrossingController.pedestrianCounter > 0) { reversed = true; stopped = false; } } else { stopped = false; reversed = false; } pedestrianController.reversed = reversed; pedestrianController.stopped = stopped; } }
void startGrabEnum(PedestrianController pedestrianRef) { Transform destination = GetPedestrianBackDestination(); GrabEnumRef = InterpPedestrian(pedestrianRef, destination); StartCoroutine(GrabEnumRef); }
public void DespawnPed(PedestrianController ped) { ped.gameObject.SetActive(false); ActivePedCount--; ped.transform.position = transform.position; ped.transform.rotation = Quaternion.identity; }
// Update is called once per frame void FixedUpdate() { if (!parent.running) { return; } if (cooldown <= 0) { PedestrianController tc = Instantiate(pedestrianPrefab, transform.position, Quaternion.identity); tc.transform.parent = parent.terrainObject.transform; tc.parent = parent; tc.direction = direction; tc.squirrel = squirrel; //tc.SetFlip(); cooldown = Random.Range(minCooldown, maxCooldown); } cooldown -= 1; if (transform.position.x < -1) { Destroy(gameObject); } }
private void OnTriggerExit(Collider other) { if (other.gameObject.tag == Strings.pedestrianCrossing) { PedestrianController pedestrianController = pedestrian.GetComponent <PedestrianController>(); pedestrianCrossing = null; pedestrianController.reversed = false; pedestrianController.stopped = false; } }
public void SolveInteraction() { PedestrianController agent = GetComponent <PedestrianController>(); PedCam.transform.position = new Vector3(agent.position.x, agent.height, agent.position.y); float sceneroty = 90 - agent.lookOrientation * 57.29577951f; Quaternion rot = Quaternion.AngleAxis(sceneroty, new Vector3(0, 1, 0)); PedCam.transform.rotation = rot; float o = agent.orientation; float rotation = -o + 1.57f; Matrix2 rmat = Matrix2.IdentityMatrix(); rmat.MakeRotation(rotation); Vector4 _g_agent_rot_mat = new Vector4(rmat[0, 0], rmat[0, 1], rmat[1, 0], rmat[1, 1]); float speed = agent.velocity.magnitude; if (speed == 0) { speed = 0.1f; } Vector2 _g_agent_velocity = (agent.orientationVec * speed) * rmat; Vector2 _g_agent_velocity_goal = (agent.dirToGoal * agent.speedComfort) * rmat; float _g_agent_pa = agent.personalArea; float _g_agent_ttg = agent.ttg; int _g_agent_id = 0; int _g_agent_aid = GetComponent <PedVisionCamera>().a_id; pedestrianMaterial.SetVector("_g_agent_rot_mat", _g_agent_rot_mat); pedestrianMaterial.SetVector("_g_agent_velocity", _g_agent_velocity); pedestrianMaterial.SetVector("_g_agent_velocity_goal", _g_agent_velocity_goal); pedestrianMaterial.SetFloat("_g_agent_pa", _g_agent_pa); pedestrianMaterial.SetFloat("_g_agent_ttg", _g_agent_ttg); pedestrianMaterial.SetInt("_g_agent_id", _g_agent_id); pedestrianMaterial.SetInt("_g_agent_aid", _g_agent_aid); Graphics.DrawMeshInstanced(pedProxy.Mesh, 0, pedestrianMaterial, idents, null, UnityEngine.Rendering.ShadowCastingMode.On, false, LayerMask.NameToLayer("Pedestrians")); PedCam.Render(); }
public void DespawnPedestrianApi(PedestrianController ped) { ped.StopPEDCoroutines(); if (SimulatorManager.Instance.Network.IsMaster) { var index = currentPedPool.FindIndex(pedestrian => pedestrian.gameObject == ped.gameObject); BroadcastMessage(new Message(Key, GetDespawnMessage(index), MessageType.ReliableUnordered)); } currentPedPool.Remove(ped); Destroy(ped.gameObject); }
IEnumerator InterpPedestrian(PedestrianController pedestrianRef, Transform destination) { bGrabEnumRunning = true; int testFactor; if (PedestrianRefs.Count == 0) { testFactor = -1; } else { testFactor = 1; } Vector3 dir = (destination.position + ((destination.up * testFactor) * 0.25f)) - pedestrianRef.transform.position; float mag = dir.magnitude; float timer = 0.0f; while (timer < 0.5f) { dir = (destination.position + ((destination.up * testFactor) * 0.25f)) - pedestrianRef.transform.position; mag = dir.magnitude; pedestrianRef.transform.position += (dir.normalized * 20.0f) * Time.deltaTime; timer += 0.1f; yield return(new WaitForSeconds(0.01f)); } pedestrianRef.transform.position = (destination.position + ((destination.up * testFactor) * 0.25f)); pedestrianRef.transform.rotation = PedestrianParent.rotation; PedestrianQueue.Remove(pedestrianRef); PedestrianRefs.Add(pedestrianRef); pedestrianRef.transform.parent = PedestrianParent.transform; MaxSpeed -= PedestrianWeight; if (MaxSpeed <= 0.0f) { MaxSpeed = PedestrianWeight; } currentJumpStrength -= PedestrianJumpWeight; if (currentJumpStrength <= 0.0f) { currentJumpStrength = PedestrianJumpWeight; } if (PedestrianQueue.Count > 0) { startGrabEnum(PedestrianQueue[PedestrianQueue.Count - 1]); } else { bGrabEnumRunning = false; } }
private void SpawnNewPedestrian() { Vector3 spawnPoint = getSpawnEndPoint(); GameObject pedestrian = GameObject.Instantiate(person_prefab, spawnPoint, Quaternion.identity, persons.transform); pedestrian.name = "ped_" + pedestrianCount; PedestrianController pc = pedestrian.AddComponent <PedestrianController>(); pc.startPos = spawnPoint; pc.endPos = getSpawnEndPoint(); pedestrianCount++; }
private void SpawnPedestrian() { if (availableSourcesForPedestrians.Count == 0) { foreach (Transform source in sourcesForPedestrians) { if (!source.gameObject.GetComponent <SourceForPedestrians>().busy) { availableSourcesForPedestrians.Add(source); } } } if (availableSourcesForPedestrians.Count == 0) { return; } pedestrianPrefab.SetActive(false); Transform randomSource = availableSourcesForPedestrians[Random.Range(0, availableSourcesForPedestrians.Count)]; availableSourcesForPedestrians.Remove(randomSource); GameObject pedestrian = Instantiate(pedestrianPrefab, randomSource.position, Quaternion.identity); PedestrianController pedestrianController = pedestrian.GetComponent <PedestrianController>(); pedestrianController.OnDestroy.AddListener(PedestrianDestroyed); pedestrian.transform.position = new Vector3(randomSource.transform.position.x, 0.1f, randomSource.transform.position.z); switch (randomSource.gameObject.tag) { case Strings.sourceWest: pedestrian.transform.Rotate(0f, 90f, 0f); break; case Strings.sourceEast: pedestrian.transform.Rotate(0f, -90f, 0f); break; default: break; } pedestrianCounter++; pedestrian.SetActive(true); }
IEnumerator SpawnOnTimer(int x) { yield return(new WaitForSeconds(Random.Range(0f, spawnTimerLimit))); if (x == 0) { //Spawn on top GameObject newPedestrian = Instantiate(customerObject, RandomPointsInBounds(topCollider.bounds), Quaternion.identity); pedestrianController = newPedestrian.GetComponent <PedestrianController>(); pedestrianController.SetGoal(botGoal); } else { //Spawn on bottom GameObject newPedestrian = Instantiate(customerObject, RandomPointsInBounds(botCollider.bounds), Quaternion.identity); pedestrianController = newPedestrian.GetComponent <PedestrianController>(); pedestrianController.SetGoal(topGoal); } }
private void Start() { PedControl = GetComponent <PedestrianController>(); cam = Camera.main; }
IEnumerator DropPedestrian(PedestrianController pedestrianRef, GameObject destination) { var randomDestination = this.transform.position; if (destination == null) { saveAllEarly(); } else { randomDestination = ReturnRandomVectorWithinBounds(destination); } Vector3 dir = randomDestination - pedestrianRef.transform.position; float mag = dir.magnitude; //while (mag > 0.5f) //{ // dir = randomDestination - pedestrianRef.transform.position; // mag = dir.magnitude; // pedestrianRef.transform.position += (dir.normalized * 50.0f) * Time.deltaTime; // yield return new WaitForSeconds(0.01f); //} pedestrianRef.transform.position = randomDestination; yield return(new WaitForSeconds(0.1f)); GameManagerScript.Instance.AddPeopleSaved(1); PedestrianRefs.Remove(pedestrianRef); MaxSpeed += PedestrianWeight; if (MaxSpeed > StartingMaxSpeed) { MaxSpeed = StartingMaxSpeed; } currentJumpStrength += PedestrianJumpWeight; if (currentJumpStrength > StartJumpStrength) { currentJumpStrength = StartJumpStrength; } if (destination == null) { saveAllEarly(); } else { pedestrianRef.transform.parent = destination.transform; pedestrianRef.BeenDroppedOff(MyRigidBody.transform); if (PedestrianRefs.Count > 0) { DropOffManual(destination); } else { bDropEnumRunning = false; currentJumpStrength = StartJumpStrength; MaxSpeed = StartingMaxSpeed; } } }
/// <summary> /// Assigns a character which this script will keep informed about presence of /// other Rigidbodies. /// </summary> void Start() { pedestrianScript = transform.parent.GetComponent<PedestrianController>(); }
private PedestrianController pedestrianScript;//character which will be notified about presence of another Rigidbody /// <summary> /// Assigns a character which this script will keep informed about presence of /// other Rigidbodies. /// </summary> void Start() { pedestrianScript = transform.parent.GetComponent <PedestrianController>(); }
private void Awake() { controller = GetComponent <PedestrianController>(); }
void OnCollisionEnter(Collision col) { Debug.Log("tag name " + col.collider.tag); if (col.collider.tag == "Pedestrian") { Rigidbody rb = col.gameObject.GetComponent <Rigidbody>(); rb.isKinematic = false; PedestrianController pedestrian = col.gameObject.transform.GetComponentInParent <PedestrianController>(); pedestrian.enabled = false; col.collider.attachedRigidbody.AddForce(1, 1, 500, ForceMode.Acceleration); Renderer renderer = col.gameObject.transform.Find("Cube").GetComponent <Renderer>(); Color color = renderer.material.color; Color blink = Color.red; //collision sound AudioSource[] sounds = GetComponents <AudioSource>(); crashSound = sounds[1]; StartCoroutine(PlaySound(crashSound)); StartCoroutine(Blink(renderer, color, blink)); pedestrianHit++; Debug.Log("Hit a pedestrian!"); } if (col.collider.tag == "AICar") { AICarController aiCar = col.gameObject.GetComponent <AICarController>(); aiCar.enabled = false; Renderer renderer = col.gameObject.GetComponent <Renderer>(); Color color = renderer.material.color; Color blink = Color.black; //collision sound AudioSource[] sounds = GetComponents <AudioSource>(); crashSound = sounds[0]; StartCoroutine(PlaySound(crashSound)); //changing color StartCoroutine(Blink(renderer, color, blink)); carHit++; Debug.Log("Hit a car!"); } if (col.collider.tag == "Wall") { Renderer renderer = col.gameObject.GetComponent <Renderer>(); Color color = renderer.material.color; Color blink = Color.yellow; //collision sound AudioSource[] sounds = GetComponents <AudioSource>(); crashSound = sounds[0]; StartCoroutine(PlaySound(crashSound)); StartCoroutine(Blink(renderer, color, blink)); wallHit++; Debug.Log("Hit a wall!"); } if (col.collider.tag == "StreetObject") { Renderer renderer = col.gameObject.GetComponent <Renderer>(); Color color = renderer.material.color; Color blink = Color.blue; //collision sound AudioSource[] sounds = GetComponents <AudioSource>(); crashSound = sounds[0]; StartCoroutine(PlaySound(crashSound)); StartCoroutine(Blink(renderer, color, blink)); streetObjectHit++; Debug.Log("Hit a street object!"); } }
IEnumerator AddPedestrianAsync() { ResourceRequest request = Resources.LoadAsync("Pedestrians/"+gc.returnRandomPassenger(), typeof(GameObject)); yield return request; p = Instantiate(request.asset as GameObject, transform.position, Quaternion.Euler(0,0,0)) as GameObject; pc = p.GetComponent<PedestrianController> (); pc.isPassenger = true; pc.pp = this; }
public void DespawnPedestrianApi(PedestrianController ped) { ped.StopPEDCoroutines(); currentPedPool.Remove(ped); Destroy(ped.gameObject); }