The effect should be like the character is rotating on the y axis smooth maybe randomly so it will looks like the character is looking outside.
This is a screenshot of the character looking out the window. And I want to make as much as realistic.
Like he is watching the view out the window. I don’t want him to move only to make it looks like it’s looking outside investigating the view outside.
Screenshot of the character this big round thing with the blue and green lights is the character :
Now he is facing the window. The camera is positioned out of the window.
Now I want that Navi(This is the character name) to be rotate on the y axis I think only the y axis from left to right directions randomly smooth and to make effect like he is looking the view outside the window.
Not sure if I should make some animation for that or just to use a script.
I tried first this script. The script is attached to the Navi character :
IEnumerator Rotates()
{
while (stopRotation == true)
{
float rotateY = Random.Range(-90, 270);
transform.eulerAngles = new Vector3(0, rotateY, 0);
yield return new WaitForSeconds(speed);
}
}
In the Start :
void Start()
{
StartCoroutine(Rotates());
}
But this make the object the Navi to rotate randomly but only to the left direction. And not so smooth.
Then I tried this :
IEnumerator DoLookAround()
{
float lookPeriod = 5f; // change look every 5 seconds
float maxRotationSpeed = 90f; // turn no faster than 90 degrees per second
Vector3 neutralForward = transform.forward;
while(true)
{
float timeToNextLook = lookPeriod;
while (timeToNextLook > 0) {
// Get random offset from forward
float targetYRotation = Random.Range(-90f, 90f);
// calculate target rotation
Quaternion targetRotation = Quaternion.LookRotation(neutralForward, transform.up)
* Quaternion.AngleAxis(targetYRotation, Vector3.up);
// rotate towards target limited by speed
Quaternion newRotation = Quaternion.RotateTowards(transform.rotation, targetRotation, maxRotationSpeed * Time.deltaTime);
timeToNextLook -= Time.deltaTime;
yield return null;
}
}
}
And in the Start :
StartCoroutine("DoLookAround");
But this code didn’t do anything. The Navi is not rotating at all.
I want to make as much as possible realistic looking effect.