Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityStandardAssets.CrossPlatformInput;
- public class MovingCar : MonoBehaviour
- {
- public Text TxtSpeed;
- public WheelCollider front_left;
- public WheelCollider front_right;
- public WheelCollider back_left;
- public WheelCollider back_right;
- public Transform FL;
- public Transform FR;
- public Transform BL;
- public Transform BR;
- public float Torque;
- public float speed;
- public float MaxSpeed = 200f;
- public int Brake = 10000;
- public float coefAcceleration = 10f;
- public float WheelAngleMax = 10f;
- public float DAmax = 40f;
- public bool freinge = false;
- public GameObject BackLight;
- private void Start()
- {
- GetComponent<Rigidbody>().centerOfMass = new Vector3(0f, -0.9f, 0.2f);
- }
- void Update()
- {
- float Val_path = speed / MaxSpeed + 1.5f;
- speed = GetComponent<Rigidbody>().velocity.magnitude * 3.6f;
- TxtSpeed.text = "Speed " + (int)speed;
- //Acceleration
- if (CrossPlatformInputManager.GetAxis("Horizontal") > 0 && (speed < MaxSpeed))
- {
- if (!freinge)
- {
- front_right.brakeTorque = 0;
- front_left.brakeTorque = 0;
- back_left.brakeTorque = 0;
- back_right.brakeTorque = 0;
- back_left.motorTorque = CrossPlatformInputManager.GetAxis("Vertical") * Torque * coefAcceleration * Time.deltaTime;
- back_right.motorTorque = CrossPlatformInputManager.GetAxis("Vertical") * Torque * coefAcceleration * Time.deltaTime;
- }
- }
- if (CrossPlatformInputManager.GetAxis("Horizontal") == 0 && !freinge || speed > MaxSpeed)
- {
- if (GetComponent<Rigidbody>().velocity.y > 0)
- {
- back_left.motorTorque = -1000;
- back_right.motorTorque = -1000;
- }
- else
- {
- back_left.brakeTorque = 5000;
- back_right.brakeTorque = 5000;
- }
- }
- if (CrossPlatformInputManager.GetButton("Jump"))
- {
- freinge = true;
- BackLight.SetActive(true);
- back_left.brakeTorque = Mathf.Infinity;
- back_right.brakeTorque = Mathf.Infinity;
- front_left.brakeTorque = Mathf.Infinity;
- front_right.brakeTorque = Mathf.Infinity;
- back_left.motorTorque = 0;
- back_right.motorTorque = 0;
- }
- else
- {
- freinge = false;
- BackLight.SetActive(false);
- }
- if (CrossPlatformInputManager.GetAxis("Horizontal") < 0)
- {
- front_right.brakeTorque = 0;
- front_left.brakeTorque = 0;
- back_left.brakeTorque = 0;
- back_right.brakeTorque = 0;
- back_left.motorTorque = CrossPlatformInputManager.GetAxis("Vertical") * Torque * coefAcceleration * Time.deltaTime;
- back_right.motorTorque = CrossPlatformInputManager.GetAxis("Vertical") * Torque * coefAcceleration * Time.deltaTime;
- }
- float DA = (((WheelAngleMax - DAmax) / MaxSpeed) * speed) + DAmax;
- front_left.steerAngle = CrossPlatformInputManager.GetAxis("Horizontal") * DA;
- front_right.steerAngle = CrossPlatformInputManager.GetAxis("Horizontal") * DA;
- FL.Rotate(front_left.rpm / 60 * 360 * Time.deltaTime, 0, 0);
- FR.Rotate(front_right.rpm / 60 * 360 * Time.deltaTime, 0, 0);
- BL.Rotate(back_left.rpm / 60 * 360 * Time.deltaTime, 0, 0);
- BR.Rotate(back_right.rpm / 60 * 360 * Time.deltaTime, 0, 0);
- FL.localEulerAngles = new Vector3(FL.localEulerAngles.x, front_left.steerAngle - FL.localEulerAngles.z, FL.localEulerAngles.z);
- FR.localEulerAngles = new Vector3(FR.localEulerAngles.x, front_right.steerAngle - FR.localEulerAngles.z, FR.localEulerAngles.z);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement