- Home /
Question by
Prajwal_S · Mar 04 at 04:45 AM ·
transformquaternioneuleranglesrotation axistransform.rotation
Increment Car Rotation along with steering Wheel
I am trying to build a car simulator in steam VR, I want the car and wheel to rotate by 30 degrees when I rotate the steering by 360, The problem I am facing is when I rotate the steering the 2nd time the car resets back to its original rotation angle that is at 0 to 30 degree again. How can I increment the angles. Below is the code that I tried to increment the angles but it not workingas the posFinal and posInitial are only varying from -0.4 to 0.4.
using System.Collections; using System.Collections.Generic; using UnityEngine; using Valve.VR.InteractionSystem; [RequireComponent(typeof(Interactable))] public class RotateWheel : MonoBehaviour {
public Transform Steer;
public Transform Wheel2;
public Transform car;
float scalingFactor = 0.5f;
public float posInitial; public float posFinal; float temp;
void Start()
{
posInitial = 0f;
posFinal = Steer.transform.rotation.y;
car.transform.eulerAngles = new Vector3(0, 0, 0);
Wheel2.transform.eulerAngles=new Vector3(0,0,0);
}
private void FixedUpdate()
{
Wheel2.transform.eulerAngles = new Vector3(-0, ((car.transform.eulerAngles.y+(posFinal-posInitial) )*30f/360), 0);
car.transform.rotation = Quaternion.Slerp(Wheel2.transform.rotation, Quaternion.identity, (Time.deltaTime *5) / scalingFactor);
temp = posInitial;
posInitial = posFinal;
posFinal = Steer.transform.rotation.y;
}
Comment