/// <summary> /// Sets the <seealso cref="SpriteAnimationStatus"/>. /// </summary> /// <param name="status">The new status to use</param> private void SetAnimationTarget(SpriteAnimationStatus status) { this.progress = 0.0f; this.endStatus = status; float[] currentRotations = new float[this.spriteManager.animatedTransforms.Length]; for (int i = 0; i < this.spriteManager.animatedTransforms.Length; i++) { currentRotations[i] = RotationExtension.WrapDegrees(this.spriteManager.animatedTransforms[i].localEulerAngles.z); } this.startStatus = new SpriteAnimationStatus( 0.0f, this.spriteManager.bodyTransform.localPosition, currentRotations); }
/// <summary> /// Called by Unity once every frame after all Updates and FixedUpdates have been executed. /// </summary> private void FixedUpdate() { if (this.following != null) { float distance = this.PreferedDistance; RaycastHit raycastHit; Vector3 rayCastDirection = this.transform.position - this.following.position; rayCastDirection.y = 0.0f; if (Physics.Raycast( this.following.position, rayCastDirection, out raycastHit, distance, this.opaqueLayerMask)) { distance = (raycastHit.point - this.following.position).magnitude; } Vector3 currentRotation = RotationExtension.WrapDegrees(this.transform.eulerAngles); this.transform.LookAt(this.following); this.transform.position += this.transform.right * Input.GetAxis("CameraHorizontal") * Time.fixedDeltaTime * this.manualControlSpeed; Vector3 targetRotation = RotationExtension.WrapDegrees(this.transform.eulerAngles); Vector3 thisToFollowing = this.transform.forward; thisToFollowing.y = 0.0f; thisToFollowing.Normalize(); Vector3 newPosition = MathExtension.ExponentialLerp( this.transform.position, this.following.position - thisToFollowing * distance, this.movementSpeedBase, Time.fixedDeltaTime); newPosition.y = this.following.position.y + this.PreferedHeight; this.transform.position = newPosition; this.transform.eulerAngles = RotationExtension.ExponentialLerpRotation( currentRotation, targetRotation, this.rotationSpeedBase, Time.fixedDeltaTime); } }