I’m trying to make simple ball game where player is supposed to roll a ball. I get ball rolling, that’s not a problem but I’m unable to make it “speed up”.
This works so that ball accelerates quite quickly to maxspeed and stays there. But I would like to speed up more when axis button is kept pressed for longer times. How I can achieve that?
You will have to record the time the keys are pressed.
You can use an if-statement to check if a key/axis is pressed and Time.deltaTime to check how much time passed since the frame is complete.
void Update () {
if( Input.GetAxis(" --the axis you want to check-- ") != 0 ){
timePressed += Time.deltaTime; //make a new var to keep track of the time.
increaseMultiplier();
}
else{
timePressed = 0; //The button is not being pressed anymore.
decreaseMultiplier();
}
}
You will have to make a multiplier variable to apply to the speed of the
object and adjust that value.
I hope this helps.
Apparently rigidbody has defined maximum angular velocity (7 by default). I can change it but then feeling of rotation is something that I do not want.
Maybe I should use force (not torque) and do rotating ball using transform?