Advertisement
Diamond32_Tutoriales

TruckEngine

Dec 19th, 2022 (edited)
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1.  
  2. using UdonSharp;
  3. using UnityEngine;
  4. using VRC.SDKBase;
  5. using VRC.Udon;
  6.  
  7. public class TruckEngine : UdonSharpBehaviour
  8. {
  9. public WheelCollider WheelFL;
  10. public WheelCollider WheelFR;
  11. public WheelCollider WheelRL;
  12. public WheelCollider WheelRR;
  13. public Transform WheelFLtrans;
  14. public Transform WheelFRtrans;
  15. public Transform WheelRLtrans;
  16. public Transform WheelRRtrans;
  17. public Vector3 eulertest;
  18. public float maxFwdSpeed = -3000;
  19. public float maxBwdSpeed = 1000f;
  20. public float gravity = 9.8f;
  21. public bool braked = false;
  22. public float maxBrakeTorque = 500;
  23. private Rigidbody rb;
  24. public Transform centreofmass;
  25. public float maxTorque = 1000;
  26.  
  27.  
  28. void Start()
  29. {
  30. rb = GetComponent<Rigidbody>();
  31. rb.centerOfMass = centreofmass.transform.localPosition;
  32. }
  33.  
  34. void FixedUpdate()
  35. {
  36. if (!braked)
  37. {
  38. WheelFL.brakeTorque = 0;
  39. WheelFR.brakeTorque = 0;
  40. WheelRL.brakeTorque = 0;
  41. WheelRR.brakeTorque = 0;
  42. }
  43.  
  44. WheelRR.motorTorque = maxTorque * Input.GetAxis("Vertical");
  45. WheelRL.motorTorque = maxTorque * Input.GetAxis("Vertical");
  46.  
  47. WheelFL.steerAngle = 30 * (Input.GetAxis("Horizontal"));
  48. WheelFR.steerAngle = 30 * Input.GetAxis("Horizontal");
  49. }
  50. void Update()
  51. {
  52. HandBrake();
  53.  
  54. //for tyre rotate
  55. WheelFLtrans.Rotate(WheelFL.rpm / 60 * 360 * Time.deltaTime, 0, 0);
  56. WheelFRtrans.Rotate(WheelFR.rpm / 60 * 360 * Time.deltaTime, 0, 0);
  57. WheelRLtrans.Rotate(WheelRL.rpm / 60 * 360 * Time.deltaTime, 0, 0);
  58. WheelRRtrans.Rotate(WheelRL.rpm / 60 * 360 * Time.deltaTime, 0, 0);
  59.  
  60. Vector3 temp = WheelFLtrans.localEulerAngles;
  61. Vector3 temp1 = WheelFRtrans.localEulerAngles;
  62. temp.y = WheelFL.steerAngle - (WheelFLtrans.localEulerAngles.z);
  63. WheelFLtrans.localEulerAngles = temp;
  64. temp1.y = WheelFR.steerAngle - WheelFRtrans.localEulerAngles.z;
  65. WheelFRtrans.localEulerAngles = temp1;
  66. eulertest = WheelFLtrans.localEulerAngles;
  67. }
  68. void HandBrake()
  69. {
  70.  
  71. if (Input.GetButton("Jump"))
  72. {
  73. braked = true;
  74. }
  75. else
  76. {
  77. braked = false;
  78. }
  79. if (braked)
  80. {
  81.  
  82. WheelRL.brakeTorque = maxBrakeTorque * 20;//0000;
  83. WheelRR.brakeTorque = maxBrakeTorque * 20;//0000;
  84. WheelRL.motorTorque = 0;
  85. WheelRR.motorTorque = 0;
  86. }
  87. }
  88.  
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement