- Home /
How to make my player object increase its speed as it moves.
I am making a game based on speed. It is a ball that moves slowly at the start of a level, but increases in speed as it moves. Only problem is, I have no idea how to make in increase in speed with the code I have written (Based on the Brackeys make a game tutorial). Here is the code I have. I would also like the incline of platforms to affect the speed. Thank you in advance!
#pragma strict
var rotationSpeed = 100;
var jumpHeight = 4;
private var isFalling = false;
function Update ()
{
//Handle ball rotation
var rotation : float = Input.GetAxis ("Horizontal") * rotationSpeed;
rotation *= Time.deltaTime;
rigidbody.AddRelativeTorque (Vector3.back * rotation);
//Handle Jump
if (Input.GetKeyDown(KeyCode.Space) && isFalling == false)
{
rigidbody.velocity.y = jumpHeight;
isFalling = true;
}
}
function OnCollisionStay ()
{
isFalling = false;
}
Answer by Naphier · Feb 08, 2015 at 06:26 AM
Check rigidbody.angularVelocity In the Project settings => Physics there is max angular velocity. You might be hitting it.
Also I'd suggest this formula for your rotation factor:
rotation = rotation + maxRotation * Time.deltaTime / levelDuration;
rotation = Mathf.Clamp(rotation , minRotation , maxRotation);
That will give you a lot more control as level duration is the time you want it to take to get up to maxRotation from, I assume, 0.
Your answer
![](https://koobas.hobune.stream/wayback/20220613182752im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Trying to deactivate a script when I'm not in the collider area 1 Answer
Tag object change position 1 Answer
How to find tags in scene? 1 Answer
Two cameras and switching 2 Answers