Hello everyone,
I am trying to lerp 4 tires rotation without effecting by parent car body rotation. How to achieve this?
This is how tires rotations should look like. I disabled car body rotation that’s why it’s working perfectly fine.
This is what happening when I am rotating car body also:
This is my script attached to each tire:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MenuTyreRotate : MonoBehaviour
{
Quaternion tyreLand;
Quaternion tyreAir;
void OnEnable()
{
tyreLand = transform.GetChild(0).GetComponent<Transform>().rotation;
tyreAir = Quaternion.identity;
StartCoroutine(AirToLand());
}
IEnumerator AirToLand()
{
var t = 0f;
while (t < 1f)
{
t += 1 * Time.deltaTime;
transform.rotation = Quaternion.Lerp (tyreAir, tyreLand, t);
yield return null;
}
transform.rotation = tyreLand;
StartCoroutine(LandToAir());
}
IEnumerator LandToAir()
{
var t = 0f;
while (t < 1f)
{
t += 1 * Time.deltaTime;
transform.rotation = Quaternion.Lerp (tyreLand, tyreAir, t);
yield return null;
}
transform.rotation = tyreAir;
StartCoroutine(AirToLand());
}
}