Advertisement
Guest User

UnityVr help

a guest
Mar 1st, 2025
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.XR.Interaction.Toolkit;
  3.  
  4. public class SteeringWheelController: MonoBehaviour
  5. {
  6. [Header("Configuração do Volante")]
  7. [Tooltip("Angulo mínimo (para a esquerda)")]
  8. public float minRotation = -90f;
  9. [Tooltip("Ângulo máximo (para a direita)")]
  10. public float maxRotation 90f;
  11. [Tooltip("Zona morta (em graus) para evitar pequenas oscilações")]
  12. public float deadzone = 5f;
  13. [HideInInspector]
  14. [Tooltip("Valor final do ângulo de direção, usado pelo carro")]
  15. public float steeringAngle 0f;
  16. private Quaternion initiallLocalRotation;
  17. void Awake()
  18. {
  19. initialLocalRotation = transform.localRotation;
  20. }
  21. void Update()
  22. {
  23. float currenty transform.localEulerAngles.y;
  24. if (currentY > 180f)
  25. currentY 360f;
  26. if (Mathf.Abs(currentY) < deadzone)
  27. currenYy 0f;
  28. currentY = Mathf.Clamp(currentY, minRotation, maxRotation); steeringAngle = currentY;
  29. transform.localRotation = Quaternion.Euler(initialLocalRotation.eulerAngles.x, currentY, initialLocalRotation.eulerAngles.z);
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement