How To Accelerate/Decelerate Gradually With Torque GetAxis

Hi guys, I’m really sorry to be doing this but I’m really lost and I’ve been searching Google and Unity Answers for a couple of weeks for the answer to this problem.

Basically I have a ball rolling game that I apply torque to move the player, it’s using GetAxis Horizontal and Vertical, which I would have thought should have been easy to do this but everything I find on AddTorque or even AddForce for acceleration appears to only work for GetKey.insert arrow keys here and so-forth.

I’m needing a solution that uses GetAxis that essentially adds a good inertia to my acceleration and deceleration in any angle the axis can be pointed in at any given time.

Here is what I have, sorry I don’t have a half-baked solution in there somewhere, I’m literally at a loss:

void FixedUpdate()
        if (onGround)

            Vector3 torqueVector = (Input.GetAxis("Horizontal") * -mainCamera.transform.forward) + (Input.GetAxis("Vertical") * mainCamera.transform.right);
            GetComponent<Rigidbody>().AddTorque(torqueVector.normalized * accRate * Time.deltaTime, ForceMode.Acceleration);

            dir.x = ((Input.GetAxis("Vertical") * flySpeed) * Time.deltaTime);
            dir.z = ((Input.GetAxis("Horizontal") * flySpeed) * Time.deltaTime);

            GetComponent<Rigidbody>().velocity += (mainCamera.transform.right * dir.z + new Vector3(mainCamera.transform.forward.x, 0, Camera.main.transform.forward.z) * dir.x);

            Vector3 torqueVector = (Input.GetAxis("Horizontal") * -mainCamera.transform.forward) + (Input.GetAxis("Vertical") * mainCamera.transform.right);
            GetComponent<Rigidbody>().AddTorque(torqueVector.normalized * accRate, ForceMode.Acceleration);


The ‘else’ part is for when it’s in the air, the player is allowed to AddForce so they can move slightly in the air while also able to manipulate torque.

I hope one of you brilliant people out there can help me out, I’d be greatly appreciative!

I’ve done something similar, for rotating an object, using AddRelativeTorque based on mouse/keyboard input.

float myDesiredSpeed = maxYawSpeed * yawRotation
parentRigidbody.AddRelativeTorque(0, myDesiredSpeed * Mathf.Rad2Deg, 0, ForceMode.Impulse)

yawRotation is a value between 0 and 1.0, taken from the joystick/mouse.
maxRotSpeed is the maximum rotation speed in Radians Per Second.

As you can guess this only works on a single rotation and you can add another axis easy enough or however you like.