Hi all,
I am trying to make a car dyno where a vehicle stays stationary while the wheels accelerate and rotate faster as the car reaches high speeds.
To see a dyno in action: http://www.youtube.com/watch?v=N1Zwa07f0rg
I have used the car tutorial and I would have liked to use it but I cant seem to get the car to stay stationary. If I turn the rigidbody to kinematic, the wheels dont behave properly I think due to the fact that the wheel colliders need something to interact with to cause friction. There is also a lot of functionality in there that is not needed so I thought it would be easy to just have a script that rotates the rear wheels without the need for wheel colliders.
In psuedocode I think it would go like this:
When the up button is held the wheel starts rotating around the z axis.
The longer the button is held, the faster the wheel rotates.
When the button is released, the acceleration stops and the wheel keeps spinning until it slows and stops naturally.
I have got it so that when the button isnt pressed, the wheel will gradually return to stationary but dont think it looks that natural. I read that you could use add torque to cause it to behave right but it doesnt seem to work. Heres my code:
using UnityEngine;
using System.Collections;
public class SpinWheels : MonoBehaviour {
public float speedUp = 0.0F;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void FixedUpdate () {
if(Input.GetKey("up"))
{
speedUp += 0.1F;
transform.Rotate(Vector3.right * speedUp);
}
else
{
//rigidbody.AddTorque( Vector3.forward);
transform.Rotate(Vector3.right * speedUp);
speedUp -= 0.1F;
}
if (speedUp <=0.0F)
{
speedUp = 0.0F;
}
}
}
Also, any idea as to how to add gears into the mix, so that when a second button is pressed, we can go up a gear and faster ( I realise that I will probably just need to put a max value on speedUp for each gear setting but wondering if there would be a better way to do it)?
Thanks