- Home /
How to make engine accelerate by 1 ?
I'm making a flight game,and i want to make engine of plane to accelerate by 1/second when "W" is down and decelerate by 1/second when "S" is down.I mean,there's minSpeed and maxSpeed,minSpeed is 0 and i want when plane isn't moving and when i will press "W" speed will accelerate to maxSpeed,not not suddenly but by 1,and when speed will be equal to maxSpeed,accelerating will stop.I need help a much.Hope you understand what i want to explain...
Comment
Best Answer
Answer by GH0STfdd · Apr 29, 2015 at 02:36 AM
Ok,i found how :))
transform.Translate(0,0,-curSpeed * Time.deltaTime);
if(startEngine == true)
{
if(Input.GetKey(KeyCode.W)&& curSpeed < maxSpeed) { curSpeed += 0.1f;}
if(Input.GetKey(KeyCode.S)){ curSpeed -= 0.1f;}
if(curSpeed >= maxSpeed)
{
curSpeed = maxSpeed;
}
if(curSpeed <= minSpeed)
{
curSpeed = stopSpeed;
}
}