WheelDrive.cs 657 B

12345678910111213141516171819202122232425262728293031
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class WheelDrive : MonoBehaviour
  5. {
  6. private WheelCollider wheelCollider;
  7. public float torque = 200;
  8. // Start is called before the first frame update
  9. void Start()
  10. {
  11. wheelCollider = GetComponent<WheelCollider>();
  12. }
  13. private void Go(float accel)
  14. {
  15. accel = Mathf.Clamp(accel, -1, 1);
  16. float thrustTorque = accel * torque;
  17. wheelCollider.motorTorque = thrustTorque;
  18. }
  19. // Update is called once per frame
  20. void Update()
  21. {
  22. float a = Input.GetAxis("Vertical");
  23. Go(a);
  24. }
  25. }