Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.XR.Interaction.Toolkit;
- public class SteeringWheelController: MonoBehaviour
- {
- [Header("Configuração do Volante")]
- [Tooltip("Angulo mínimo (para a esquerda)")]
- public float minRotation = -90f;
- [Tooltip("Ângulo máximo (para a direita)")]
- public float maxRotation 90f;
- [Tooltip("Zona morta (em graus) para evitar pequenas oscilações")]
- public float deadzone = 5f;
- [HideInInspector]
- [Tooltip("Valor final do ângulo de direção, usado pelo carro")]
- public float steeringAngle 0f;
- private Quaternion initiallLocalRotation;
- void Awake()
- {
- initialLocalRotation = transform.localRotation;
- }
- void Update()
- {
- float currenty transform.localEulerAngles.y;
- if (currentY > 180f)
- currentY 360f;
- if (Mathf.Abs(currentY) < deadzone)
- currenYy 0f;
- currentY = Mathf.Clamp(currentY, minRotation, maxRotation); steeringAngle = currentY;
- transform.localRotation = Quaternion.Euler(initialLocalRotation.eulerAngles.x, currentY, initialLocalRotation.eulerAngles.z);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement