private Vector3 RotateVector(Vector3 baseVector, float radians) { float x0 = baseVector.x; float z0 = baseVector.z; float x1 = x0 * TrigLookup.Cos(radians) - z0 * TrigLookup.Sin(radians); float z1 = x0 * TrigLookup.Sin(radians) + z0 * TrigLookup.Cos(radians); return(new Vector3(x1, baseVector.y, z1)); }
IEnumerator RotateToRoutine(Quaternion rot) { float p = 0.0f; float q = 0.0f; Quaternion initRot = this.transform.rotation; while (p < Mathf.PI) { yield return(new WaitForEndOfFrame()); q = (1 - TrigLookup.Cos(p)) / 2.0f; // Also, (cos (x + PI) + 1) / 2 this.transform.rotation = Quaternion.Lerp(initRot, rot, q); p += Time.deltaTime * this.speed * 2; } this.transform.rotation = rot; }
IEnumerator MoveToRoutine(Vector3 pos) { float p = 0.0f; float q = 0.0f; Vector3 initPos = this.transform.position; while (p < Mathf.PI) { yield return(new WaitForEndOfFrame()); q = (1 - TrigLookup.Cos(p)) / 2.0f; // Also, (cos (x + PI) + 1) / 2 this.transform.position = Vector3.Lerp(initPos, pos, q); p += Time.deltaTime * this.speed; } this.transform.position = pos; }
IEnumerator MoveToHeightLevelRoutine(GameEnum.HeightLevel heightLevel) { float startHeight = this.transform.position.y; float targetHeight = (heightLevel == GameEnum.HeightLevel.LOWER) ? DataManager.HEIGHT_LEVEL_LOWER : DataManager.HEIGHT_LEVEL_UPPER; float timer = 0.0f; float duration = 2.0f; float parametric = 0.0f; float rotationX = 0.0f; float maxRotationX = (heightLevel == GameEnum.HeightLevel.LOWER) ? 20f : -20f; while (timer < duration) { yield return(new WaitForEndOfFrame()); parametric = (TrigLookup.Sin(((timer / duration) * Mathf.PI) - Mathf.PI / 2.0f) * 0.5f) + 0.5f; rotationX = TrigLookup.Sin((timer / duration) * Mathf.PI); //Debug.Log (parametric); this.transform.position = new Vector3(this.transform.position.x, Mathf.Lerp(startHeight, targetHeight, parametric), this.transform.position.z); this.model.transform.localRotation = Quaternion.Lerp(this.model.transform.localRotation, Quaternion.Euler(rotationX * maxRotationX, this.model.transform.localRotation.y, this.model.transform.localRotation.z), parametric); timer += Time.deltaTime; } this.transform.position = new Vector3(this.transform.position.x, targetHeight, this.transform.position.z); this.model.transform.localRotation = Quaternion.Euler(0, this.model.transform.localRotation.y, this.model.transform.localRotation.z); this.heightLevel = heightLevel; this.isMovingHeight = false; /*if (this.heightLevel == GameEnum.HeightLevel.LOWER) * this.transform.position = new Vector3 (this.transform.position.x, Mathf.Lerp (this.transform.position.y, this.startPos.y, Time.deltaTime * 5), this.transform.position.z); * else if (this.heightLevel == GameEnum.HeightLevel.UPPER) * this.transform.position = new Vector3 (this.transform.position.x, Mathf.Lerp (this.transform.position.y, this.startPos.y + 10, Time.deltaTime * 5), this.transform.position.z);*/ }
// Update is called once per frame void Update() { this.transform.localPosition = new Vector3(0, TrigLookup.Sin(Time.time * this.speed) * this.variance, 0); }