Question by
Nirmal3095 · Sep 17, 2015 at 06:38 PM ·
javascript
how to Increase speed of a car.?
I'm developing a car racing game. I've used following script to move car and increase speed gradually but problem I'm facing is car is moving at constant speed.Help me to maintain speed on key down event.
var CurrentSpeed : float = 1;
var RotationSpeed : float = 10.0;
transform.Translate(Vector3.forward * Time.deltaTime * CurrentSpeed , Space.Self);
if(CurrentSpeed < 0)
{
CurrentSpeed +=100* Time.deltaTime;
}
else
{
CurrentSpeed -=100* Time.deltaTime;
}
if(Input.GetKey("w"))
{
CurrentSpeed +=Time.deltaTime;
transform.Translate(Vector3.back * Time.deltaTime * CurrentSpeed , Space.Self);
}
if(Input.GetKey("s"))
{
CurrentSpeed -= 10*Time.deltaTime;
transform.Translate(Vector3.forward * Time.deltaTime * CurrentSpeed , Space.Self);
}
if(Input.GetKey(KeyCode.LeftArrow))
{
transform.Rotate(Vector3.up * Time.deltaTime * -RotationSpeed, Space.Self);
}
if(Input.GetKey(KeyCode.RightArrow)){
transform.Rotate(Vector3.up * Time.deltaTime * RotationSpeed, Space.Self);
}`
Comment