Hello.
I’m creating a game where the player controls a ball. I’d like the ball to roll progressively faster the longer you hold down a move key.
I found that using Unity physics to move the ball makes things much smoother, so I have a Rigidbody
with a Sphere Collider
and I am only moving the player using AddTorque
to make the ball roll. With this setup, it is actually the friction contact between the ground and the ball that propels me forward. What I’ve found is that my velocity ramps up to 15 but the more torque that I add to the ball I cannot seem to get it to go any faster. I increased the friction of the ball to 100, set the drag and angular drag to zero, and made the torque increase exponentially with respect to the ball’s velocity. Nothing gets me past a speed of 15.
So do you guys think I am running into a Unity physics limitation?
I’m kinda at a loss.
Code:
void Movement ()
{
Move = Camera.transform.right*(TorqueStr*Mathf.Pow(rb.velocity.magnitude, MovePow)+MoveStartStr);
Turning = Vector3.Cross(Camera.transform.right*(TorqueStr*Mathf.Pow(rb.velocity.magnitude, MovePow)/1.5f+MoveStartStr), Vector3.up);
AirTurning = Camera.transform.right*(AirTurnStr*Mathf.Pow(Mathf.Log(rb.velocity.magnitude, 2f),2f)+1f);
if (Input.GetKey(KeyCode.W) && inAir()) {
rb.AddTorque(Move, ForceMode.Force);
}
else if (Input.GetKey(KeyCode.S) && inAir()) {
rb.AddTorque(-Move, ForceMode.Force);
}
if (Input.GetKey(KeyCode.A) && inAir()) {
rb.AddTorque(Turning, ForceMode.Force);
}
else if (Input.GetKey(KeyCode.D) && inAir()) {
rb.AddTorque(-Turning, ForceMode.Force);
}
if (Input.GetKey(KeyCode.A) && !inAir()) {
rb.AddForce(-AirTurning, ForceMode.Force);
}
else if (Input.GetKey(KeyCode.D) && !inAir()) {
rb.AddForce(AirTurning, ForceMode.Force);
}
}