- Home /
Slowly making the player go faster.
Hello, I'm rather new to the Unity scene, and well, the first thing I wanted to try was a infinite runner. However, I had a question, and that would be if it's possible to make the player slowly going faster and faster until X speed have been hit?
Yes it is, if you post your current code then maybe we can show you how to alter it to do this :)
As my current code is nothing interesting, I have been browsing around the forum, and various other sites, for quite some time, however, I have found none that seems to fit the needs. All i got for now is the basic commands for moving the player from left to right, which would be as follows:
public float speedside;
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
Vector3 movement = new Vector3 (0f, 0f, moveHorizontal);
rigidbody.AddForce (movement * speedside * Time.deltaTime);
}
I looked at this one: http://answers.unity3d.com/questions/725685/change-speed-over-time.html
however, it did raise some question about it.
You can do something like this, it is a quick fix solution but something for you to have a play around with :
private float speedside = 1.0f;
private float f$$anonymous$$ax_Speed = 100.0f;
void FixedUpdate() {
float moveHorizontal = Input.GetAxis("Horizontal");
Vector3 movement = new Vector3 (0f, 0f, moveHorizontal);
rigidbody.AddForce (movement * speedside * Time.deltaTime);
if (speedside < f$$anonymous$$ax_Speed) {
speedside = speedside + 0.01f;
}
}
Take a look at Invoke's for a better way to do the gradual speed increase, try stuff out yourself it is the best way to learn :)
Woah, thanks for the help!
Indeed, doing it your self is the best way to learn, but sometimes you just need a little help! :)