- Home /
My android car Racing game not gone to backward and forward by mobile joystick my is there,My Android car racing game not gone backward and forward by mobile joystick my code is there?
using UnityEngine; using System.Collections; using UnityEngine.UI; using UnityStandardAssets.CrossPlatformInput; public class pak : 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=100f; public int Brake = 10000; public bool Freinage = false; public float CoefAcceleration = 3f; public float CoefBrake=100; public float WheelAngleMax = 10f; public float DAMax = 40f; public GameObject BackLight; void Start() { GetComponent().centerOfMass = new Vector3(0f, -0.9f, 0.2f);
}
void Update()
{
Speed = GetComponent<Rigidbody>().velocity.magnitude * 3.6f;
if (CrossPlatformInputManager.GetAxis("Horizontal") > 0 && (Speed < MaxSpeed))
{ if (!Freinage)
{
Debug.Log("Acceleration");
front_left.brakeTorque = 0;
front_right.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 && !Freinage || Speed > MaxSpeed)
{ if (GetComponent<Rigidbody>().velocity.y > 0 || Speed > MaxSpeed)
{
back_left.motorTorque = -1000;
back_right.motorTorque = -1000;
}
else
{
back_left.motorTorque = 5000;
back_right.motorTorque = 5000;
}
}
if(CrossPlatformInputManager.GetButton("jump"))
{ BackLight.SetActive(true);
Freinage = true;
front_left.brakeTorque = Mathf.Infinity;
front_right.brakeTorque = Mathf.Infinity;
back_left.brakeTorque = Mathf.Infinity;
back_right.brakeTorque = Mathf.Infinity;
back_left.motorTorque = 0;
back_right.motorTorque = 0;
}
else
{ Freinage = false;
BackLight.SetActive(false);
}
if (CrossPlatformInputManager.GetAxis("Horizontal") < 0)
{ Debug.Log("Marche Arrirer");
front_left.brakeTorque = 0;
front_right.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;
}
//Direction
float DA = (((WheelAngleMax - DAMax) /MaxSpeed)) * Speed + DAMax;
front_left.steerAngle = CrossPlatformInputManager.GetAxis("Horizontal") * DA;
front_right.steerAngle = CrossPlatformInputManager.GetAxis("Horizontal") * DA;
//Rotation
FL.Rotate(front_left.rpm / 60 * 360 * Time.deltaTime, 0, 0);
FR.Rotate(front_left.rpm / 60 * 360 * Time.deltaTime, 0, 0);
BL.Rotate(front_left.rpm / 60 * 360 * Time.deltaTime, 0, 0);
BR.Rotate(front_left.rpm / 60 * 360 * Time.deltaTime, 0, 0);
//SteerAngle
FL.localEulerAngles = new Vector3(FL.localEulerAngles.x, front_left.steerAngle - FL.localEulerAngles.z, FL.localEulerAngles.z);
FR.localEulerAngles = new Vector3(FL.localEulerAngles.x, front_left.steerAngle - FL.localEulerAngles.z, FL.localEulerAngles.z);
}
}
Your answer
Follow this Question
Related Questions
If mobile joystick is moved , then animation transforms from idle to walk? 2 Answers
how to rotate object with joystick (Mobile) 0 Answers
how to rotate car to camera direction using wheel colliders. 1 Answer
How do I make the center of the joystick bounce back to the middle when its not being used?, 0 Answers