using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.Characters.FirstPerson;
public class RotateObject : MonoBehaviour
{
public UnityStandardAssets.ImageEffects.Blur blur;
public UnityStandardAssets.ImageEffects.BlurOptimized blurOptimized;
public FadeScript fadescript;
[SerializeField] Quaternion targetRotation; /// <summary>Rotation you want to achieve.</summary>
[SerializeField] private float s; /// <summary>Rotation duration.</summary>
private Quaternion initialRotation; /// <summary>Your GameObject's initial rotation.</summary>
private float t; /// <summary>Your 't' reference.</summary>
private FirstPersonController fpcscript;
void Awake()
{
fpcscript.enabled = false;
fpcscript = transform.GetComponent<FirstPersonController>();
initialRotation = transform.localRotation;
}
void Update()
{
if (fadescript.alphaZero == true)
{
if (t < 1.0f)
{
transform.rotation = Quaternion.Lerp(initialRotation, targetRotation, t);
t += (Time.deltaTime / s); /// Each 60 frames [optimally] t reaches 1, divided by your duration, it will reach 1 on 'x' seconds.
}
else /// Your rotation ends here:
{ /// reset 't' [if you please], and reset 'initialRotation'
initialRotation = transform.rotation;
blur.enabled = false;
blurOptimized.enabled = false;
fpcscript.enabled = true;
}
}
}
}
The script is attached to FPSController. In the Inspector the Rotation of the FPSController is: X = 7 Y = 112 Z = -31
But when i'm using a break point on the line in the Awake:
initialRotation = transform.localRotation;
I see that initialRotation values are: (-0.2, 0.8, -0.2, 0.5)
What i want to do is to rotate the transofrm from X = 7 Y = 112 Z = -31 to rotation 0,0,0 That is why i also didn't set any values to targetRotation since i want it to rotate to 0,0,0