IEnumerator OnCollisionEnter(Collision collision) { //If some child of character collides we still want the whole character. //GameObject rootObject = collision.collider.transform.root.gameObject; GameObject rootObject = collision.gameObject; Debug.Log(collision); if (collision.collider.gameObject.tag == "Player") { character.rigidbody.isKinematic = true; fatalAudio.audio.Play(); yield return(new WaitForSeconds(2)); character.rigidbody.isKinematic = false; rootObject.transform.position = Globals.respawnAt.transform.position; rootObject.transform.rotation = Globals.respawnAt.transform.rotation; camFollow.transform.rotation = Globals.respawnAt.transform.rotation; MeshMovement movement = character.GetComponent <MeshMovement>(); movement.goingForward = 1; character.GetComponent <Rigidbody>().velocity = Vector3.zero; } }
IEnumerator DoZoom() { Camera camera = GetComponentInChildren <Camera>(); Vector3 start = camera.transform.position; Vector3 end = start + camera.transform.TransformDirection(Vector3.back) * zoomAmount; if (zoomedOut) { end = start - camera.transform.TransformDirection(Vector3.back) * zoomAmount; } float t = 0.0f; float rate = 1 / zoomSeconds; MeshMovement movement = character.GetComponent <MeshMovement>(); movement.enabled = false; movement.FullStop(); while (true) { float factor = rotationCurve.Evaluate(t); Vector3 current = camera.transform.position; current = start + (end - start) * factor; camera.transform.position = current; if (t > 1.0f) { break; } t += Time.deltaTime * rate; yield return(null); } if (!zoomedOut) { zoomedOut = true; } else { zoomedOut = false; movement.enabled = true; } zooming = false; }
void OnTriggerExit(Collider other) { //If some child of character collides we still want the whole character. //GameObject rootObject = other.transform.root.gameObject; GameObject rootObject = other.gameObject; if (rootObject.tag == "Player") { camFollow.GetComponent <CameraWorldControl>().CancelRotate(); rootObject.transform.position = Globals.respawnAt.transform.position; rootObject.transform.rotation = Globals.respawnAt.transform.rotation; camFollow.transform.rotation = Globals.respawnAt.transform.rotation; MeshMovement movement = character.GetComponent <MeshMovement>(); movement.goingForward = 1; rootObject.GetComponent <Rigidbody>().velocity = Vector3.zero; } }
IEnumerator DoRotate() { float rotationAmount = rotating * 90; float t = 0.0f; float rate = 1 / rotationSeconds; float start, end, previous; MeshMovement movement = character.GetComponent <MeshMovement>(); if (!rotateY) { start = transform.eulerAngles.z; } else { start = transform.eulerAngles.y; } end = start + rotationAmount; previous = start; if (!rotateY) { character.GetComponent <Animator>().SetBool("Turning", true); } while (true) { if (cancelRotate) { cancelRotate = false; break; } float factor = rotationCurve.Evaluate(t); if (!rotateY) { transform.Rotate(-(start + (end - start) * factor - previous), 0, 0); character.transform.Rotate(movement.goingForward * -(start + (end - start) * factor - previous), 0, 0); previous = start + (end - start) * factor; } else { transform.Rotate(0, start + (end - start) * factor - previous, 0); character.transform.Rotate(0, start + (end - start) * factor - previous, 0); previous = start + (end - start) * factor; } if (Mathf.Abs(previous - end) < 0.001f) { break; //stop when we reach target angle } t += rate * Time.deltaTime; Globals.ChangeGravity(transform); yield return(null); } if (!rotateY) { character.GetComponent <Animator>().SetBool("Turning", false); } rotating = 0; }