private IEnumerator OpenDoors(bool open) { for (float elapsed = 0; elapsed < openTime; elapsed += Time.deltaTime) { while (WorldControl.IsPaused) { yield return(null); } float percent = elapsed / openTime; if (!open) { percent = 1 - percent; } float value = slideRange.GetAt(openCurve.Evaluate(percent)); leftDoor.localPosition = new Vector3(-value, leftDoor.localPosition.y, leftDoor.localPosition.z); rightDoor.localPosition = new Vector3(value, rightDoor.localPosition.y, rightDoor.localPosition.z); yield return(null); } leftDoor.localPosition = new Vector3(open ? -slideRange.max : -slideRange.min, leftDoor.localPosition.y, leftDoor.localPosition.z); rightDoor.localPosition = new Vector3(open ? slideRange.max : slideRange.min, rightDoor.localPosition.y, rightDoor.localPosition.z); if (shouldBeOpen != open) { StartCoroutine(OpenDoors(shouldBeOpen)); } else { openCoroutine = null; } }
private void OnTriggerStay(Collider other) { float height = other.bounds.size.y; float percentSubmerged = Mathf.InverseLerp(other.bounds.min.y, other.bounds.max.y, transform.position.y); float percentUnder = Mathf.InverseLerp(boxCollider.bounds.min.y, boxCollider.bounds.max.y, other.bounds.center.y); other.attachedRigidbody.AddTorque(other.attachedRigidbody.angularVelocity * -drag, ForceMode.VelocityChange); other.attachedRigidbody.AddForce(other.attachedRigidbody.velocity * -drag, ForceMode.Impulse); // other.attachedRigidbody.velocity *= drag; if (percentSubmerged < 1) { other.attachedRigidbody.AddForce(Vector3.up * force.min * percentSubmerged, ForceMode.Acceleration); } else { other.attachedRigidbody.AddForce(Vector3.up * force.GetAt(1 - percentUnder), ForceMode.Acceleration); } }