Hi
i want a speed limitation For my car script
Thank you!
using UnityEngine;
using System.Collections;
public class Car : MonoBehaviour
{
public float topSpeed = 100;
private float currentSpeed = 0;
private float pitch = 0;
public float maxTorque = 50f;
public Transform centerOfMass;
public WheelCollider[] wheelColliders = new WheelCollider[4];
public Transform[] tireMeshes = new Transform[4];
private Rigidbody m_rigidBody;
void Start()
{
m_rigidBody = GetComponent<Rigidbody>();
m_rigidBody.centerOfMass = centerOfMass.localPosition;
}
void Update()
{
currentSpeed = transform.GetComponent <Rigidbody> ().velocity.magnitude * 2.6f;
pitch = currentSpeed / topSpeed;
transform.GetComponent <AudioSource> ().pitch = pitch;
UpdateMeshesPositions();
}
void FixedUpdate()
{
float steer = Input.GetAxis("Horizontal");
float accelerate = Input.GetAxis("Vertical");
float finalAngle = steer * 45f;
wheelColliders[0].steerAngle = finalAngle;
wheelColliders[1].steerAngle = finalAngle;
for(int i = 0; i < 4; i++)
{
wheelColliders_.motorTorque = accelerate * maxTorque;_
}
}
void UpdateMeshesPositions()
{
for(int i = 0; i < 4; i++)
{
Quaternion quat;
Vector3 pos;
wheelColliders*.GetWorldPose(out pos, out quat);*
tireMeshes*.position = pos;*
tireMeshes*.rotation = quat;*
}
}
}