Advertisement
obernardovieira

[Unity] Controlar veiculo (mais recente)

Jun 17th, 2013
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.42 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4.  
  5. public class controlarvei : MonoBehaviour {
  6.     public GameObject rodad;
  7.     public GameObject rodadp;
  8.     public GameObject rodae;
  9.     public GameObject rodaep;
  10.     public GameObject rodate;
  11.     public GameObject rodatd;
  12.    
  13.     public WheelCollider rodadireita;
  14.     public WheelCollider rodaesquerda;
  15.     public float maxTorque;
  16.     public float maxAngle;
  17.    
  18.     private float actualAngle;
  19.     private float rodada;
  20.    
  21.    
  22.     // Use this for initialization
  23.     void Start () {
  24.         rigidbody.centerOfMass = new Vector3(0, 0, 0);
  25.         actualAngle=maxAngle;
  26.     }
  27.    
  28.     // Update is called once per frame
  29.     void FixedUpdate () {
  30.         if(rodadireita.rpm<-100) {
  31.             actualAngle=maxAngle/((-rodadireita.rpm)/100);
  32.         }
  33.         rodadireita.motorTorque=maxTorque*(-Input.GetAxis("Vertical"));
  34.         rodaesquerda.motorTorque=maxTorque*(-Input.GetAxis("Vertical"));
  35.         rodadireita.steerAngle=actualAngle*Input.GetAxis("Horizontal");
  36.         rodaesquerda.steerAngle=actualAngle*Input.GetAxis("Horizontal");
  37.        
  38.        
  39.         rodaep.transform.localEulerAngles = new Vector3(
  40.             rodaep.transform.localEulerAngles.x,
  41.             rodaep.transform.localEulerAngles.y,
  42.             actualAngle*Input.GetAxis("Horizontal")
  43.         );
  44.        
  45.         if(rodadireita.rpm>1||rodadireita.rpm<-1) {
  46.             rodada=rodadireita.rpm/10;
  47.             rodad.transform.Rotate(rodada,0,0);
  48.             rodae.transform.Rotate(rodada,0,0);
  49.             rodatd.transform.Rotate(rodada,0,0);
  50.             rodate.transform.Rotate(rodada,0,0);
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement