Hey i need help by my 2d car i have a car and as childreen the tire but when i make the speed to much the tire fly away from the car can you help me
Heres the car code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;
using UnityEngine.SceneManagement;
public class DrivingScript : MonoBehaviour
{
public float fuel = 1;
public float fuelconsumption = 0.1f;
public WheelJoint2D wheelFront, wheelBack;
public float SpeedForward;
public float SpeedBackward;
public float Torque;
public UnityEngine.UI.Image image;
private JointMotor2D backMotor, frontMotor;
void Start()
{
}
void Update()
{
image.fillAmount = fuel;
float X = CrossPlatformInputManager.GetAxis("Horizontal");
if (fuel > 0)
{
if (X > 0)
{
backMotor.motorSpeed = SpeedForward;
frontMotor.motorSpeed = SpeedForward;
backMotor.maxMotorTorque = Torque;
frontMotor.maxMotorTorque = Torque;
wheelFront.motor = frontMotor;
wheelBack.motor = backMotor;
}
else if (X < 0)
{
backMotor.motorSpeed = SpeedBackward;
frontMotor.motorSpeed = SpeedBackward;
backMotor.maxMotorTorque = Torque;
frontMotor.maxMotorTorque = Torque;
wheelFront.motor = frontMotor;
wheelBack.motor = backMotor;
}
else
{
backMotor.motorSpeed = 0;
frontMotor.motorSpeed = 0;
wheelFront.motor = frontMotor;
wheelBack.motor = backMotor;
}
}
else if (fuel < 0)
{
StartCoroutine(FuelLeer());
}
fuel -= fuelconsumption * Mathf.Abs(X) * Time.fixedDeltaTime;
}
IEnumerator FuelLeer()
{
yield return new WaitForSeconds(2f);
if (fuel > 0)
{
}
else if (fuel < 0)
{
SceneManager.LoadScene("Level");
}
}
}