Hello,
I am not too good with scripting in Unity and I have come across a few problems. I have tried for weeks to get it working but with no success.
Basically, I am trying to make a game where the player has to navigate a level using a wooden ball. They use the arrow keys to controll the rolling of the ball.
I have made a script using AddForce with Rigidbodies on my ball object but the ball rolls incredibly slow and takes ages to change direction.
I want to be able to have a fast acceleration and be able to change directions fast but still have a relatively low top speed.
You're on the right track, except for some specifics-
If you use ForceMode.Acceleration, there will be virtually no top speed. It's basically emulating gravity!
There isn't really an inbuilt way to give a rigidbody a 'top speed' as such- you can, however, give it relatively high drag and low mass, and it will stop moving soon after you stop putting a force on it.
Is there any reason why you need to be using discrete inputs here? Why can't you use the Input.GetAxis("Horizontal/Vertical")? If you do something like that, you could fake out your drag to give a better response time, and still control the desired velocity.
This is how I would do it:
public float desiredSpeed;
public float maximumDrag;
public float forceConstant;
void Update()
{
Vector3 forceDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
//This reduces drag when the player adds input, and makes it stop faster.
rigidbody.drag = Mathf.Lerp(maximumDrag, 0, forceDirection.magnitude);
// this reduces the amount of force that acts on the object if it is already
// moving at speed.
float forceMultiplier = Mathf.Clamp01((desiredSpeed - rigidbody.velocity.magnitude) / desiredSpeed);
// now we actually perform the push
Rigidbody.AddForce(forceDirection * (forceMultiplier * Time.deltaTime * forceConstant));
}