I need help making a ball accelerate
So this is my code for a 3D game I'm working on where you are a ball rolling left and right and u jump and stuff. My problem is I do not like having the speed be the same, because it just bothers me that the ball always rolls at a constant speed. I tried making the ball accelerate but it is not working. You can see my code for that in //Acceleration. According to unity the rotationSpeed is changing a lot, but the balls speed doesn't change and I'm not sure why. I'm pretty new to this stuff so if anyone can explain why its not working or what a good fix is that would be amazing. This is my code:
var rotationSpeed = 100;
var jumpHeight = 8;
private var isFalling = false;
function Update ()
{
//Handle Ball Rotation
var rotation : float = Input.GetAxis ("Horizontal") * rotationSpeed;
rotation *= Time.deltaTime;
GetComponent.<Rigidbody>().AddRelativeTorque (Vector3.back * rotation);
//Acceleration
rotationSpeed = (rotationSpeed + (Time.deltaTime * 500));
//Jumping
if (Input.GetKeyDown(KeyCode.W) && (isFalling == false))
{
GetComponent.<Rigidbody>().velocity.y = jumpHeight;
}
isFalling = true;
}
//This makes sure that the ball can't double jump
function OnCollisionStay ()
{
isFalling = false;
}
Your answer
Follow this Question
Related Questions
Increase variable? 0 Answers
Object jumping at high speed! 0 Answers
Stuck on a project, need help with mechanics 0 Answers
How to make sphere a cricket ball? 1 Answer
How to get static speed 1 Answer