Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UdonSharp;
- using UnityEngine;
- using VRC.SDKBase;
- using VRC.Udon;
- public class TruckEngine : UdonSharpBehaviour
- {
- public WheelCollider WheelFL;
- public WheelCollider WheelFR;
- public WheelCollider WheelRL;
- public WheelCollider WheelRR;
- public Transform WheelFLtrans;
- public Transform WheelFRtrans;
- public Transform WheelRLtrans;
- public Transform WheelRRtrans;
- public Vector3 eulertest;
- public float maxFwdSpeed = -3000;
- public float maxBwdSpeed = 1000f;
- public float gravity = 9.8f;
- public bool braked = false;
- public float maxBrakeTorque = 500;
- private Rigidbody rb;
- public Transform centreofmass;
- public float maxTorque = 1000;
- void Start()
- {
- rb = GetComponent<Rigidbody>();
- rb.centerOfMass = centreofmass.transform.localPosition;
- }
- void FixedUpdate()
- {
- if (!braked)
- {
- WheelFL.brakeTorque = 0;
- WheelFR.brakeTorque = 0;
- WheelRL.brakeTorque = 0;
- WheelRR.brakeTorque = 0;
- }
- WheelRR.motorTorque = maxTorque * Input.GetAxis("Vertical");
- WheelRL.motorTorque = maxTorque * Input.GetAxis("Vertical");
- WheelFL.steerAngle = 30 * (Input.GetAxis("Horizontal"));
- WheelFR.steerAngle = 30 * Input.GetAxis("Horizontal");
- }
- void Update()
- {
- HandBrake();
- //for tyre rotate
- WheelFLtrans.Rotate(WheelFL.rpm / 60 * 360 * Time.deltaTime, 0, 0);
- WheelFRtrans.Rotate(WheelFR.rpm / 60 * 360 * Time.deltaTime, 0, 0);
- WheelRLtrans.Rotate(WheelRL.rpm / 60 * 360 * Time.deltaTime, 0, 0);
- WheelRRtrans.Rotate(WheelRL.rpm / 60 * 360 * Time.deltaTime, 0, 0);
- Vector3 temp = WheelFLtrans.localEulerAngles;
- Vector3 temp1 = WheelFRtrans.localEulerAngles;
- temp.y = WheelFL.steerAngle - (WheelFLtrans.localEulerAngles.z);
- WheelFLtrans.localEulerAngles = temp;
- temp1.y = WheelFR.steerAngle - WheelFRtrans.localEulerAngles.z;
- WheelFRtrans.localEulerAngles = temp1;
- eulertest = WheelFLtrans.localEulerAngles;
- }
- void HandBrake()
- {
- if (Input.GetButton("Jump"))
- {
- braked = true;
- }
- else
- {
- braked = false;
- }
- if (braked)
- {
- WheelRL.brakeTorque = maxBrakeTorque * 20;//0000;
- WheelRR.brakeTorque = maxBrakeTorque * 20;//0000;
- WheelRL.motorTorque = 0;
- WheelRR.motorTorque = 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement