I have made this script to control a car in the game, I’m using rb.AddForce to make it move which i think is not a good movement method for a car in the game and in the game the acceleration is slow then accelerates to about 200 in 1 sec all of a sudden which is unrealistic, So my questions is which is the best line of code for car movement. i have also tried the vector3.forward but then it flies around in the air like crazy and it has unrealistic physics then.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class car : MonoBehaviour {
public float thrust;
public Rigidbody rb;
public Text speedText;
private float speed;
public float drag;
public float acceleration;
public float breakpower;
void Start () {
rb = GetComponent<Rigidbody>();
}
void Update () {
speedText.text = Mathf.Round(rb.velocity.magnitude * 3) + " kph";
speed -= (drag * (speed / (drag * 75)));
rb.AddForce(-transform.forward * speed * Time.deltaTime);
if(Input.GetKey ("up")) {
speed += acceleration;
}
if(Input.GetKey ("down")) {
speed-= breakpower;
}
if(Input.GetKey ("right")) {
transform.Rotate(new Vector3(0.0f,1.0f,0.0f), (3));
}
if(Input.GetKey ("left")) {
transform.Rotate(new Vector3(0.0f,-1.0f,0.0f), (3));
}
}
}