Rotating a sphere with a joystick

Hi Unity!

So I’m working on a small game where your player is essentially stationary on a small planet, as the planet moves beneath you. I’m stumped on how to translate my joystick inputs (normalized 0-1 x and y inputs) into 3D rotation. I’ve tried quite a few different methods.

What I’m essentially looking for is for the ball to roll (without actually moving) towards the direction I’m pushing the joystick. For instance: From a dead stop, with an arbitrary starting rotation, if I push the joystick to the right (Horizontal input axis ==1) then the ball should spin counter-clockwise on the y axis. Likewise for the x axis for up and down, and any combination of the two.

Here’s the code I’ve tried that I’ve gotten closest with:

    void Update()
    { 
        float moveHorizontal = CnInputManager.GetAxis("Horizontal");
        float moveVertical = CnInputManager.GetAxis("Vertical");

        //Regular rotation approach. Loses proper axis as soon as
        //both X and Y are greater than (or less than) zero at the same time
        transform.Rotate(moveHorizontal, moveVertical, 0);
    }

Here’s a diagram of what I’m looking for:

That’s a piece from my app that kinda does that. Look into World and Local rotation though

  float p=  CrossPlatformInputManager.GetAxis("Vertical") / body.velocity.magnitude*500;
            float h = CrossPlatformInputManager.GetAxis("Horizontal") / body.velocity.magnitude*500;
            body.transform.Rotate(transform.forward, -h, Space.World);
            body.transform.Rotate(transform.right,p,Space.World);

Try:

 float speed = 1f;

     void Update()  { 
         float moveHorizontal = CnInputManager.GetAxis("Horizontal");
         float moveVertical = CnInputManager.GetAxis("Vertical");
     
         //Regular rotation approach. Loses proper axis as soon as
         //both X and Y are greater than (or less than) zero at the same time
         transform.Rotate(new Vector3(moveHorizontal,moveVertical,0)
    *speed* Time.deltaTime);  }

I’ve add a speed value to better control the rotation.

transform.Rotate(moveHorizontal, moveVertical, 0);

This function will ADD to the transform’s current rotation, about each local axis, the euler angles you provide.
It is important to note that the objects local AXIS (transform.up and transform.right) will CHANGE as you do this. Calls to transform.Rotate will be around these local axis.

It sounds like you want to rotate about the WORLD Y-axis and WORLD X-axis, rather than the transform’s current axis’s. Perhaps something like this:

transform.rotation *= Quaternion.AngleAxis(moveHorizontal,Vector3.up); //add a rotation around world Y axis, to objects current rotation
transform.rotation *= Quaternion.AngleAxis(moveVertical,Vector3.right); //add a rotation around world X axis, to objects current rotation

Not positive, but i think this would also be equivalent to:

 transform.rotation *= Quaternion.Euler(moveVertical,moveHorizontal,0);