How to control camera orbit using joystick

Can someone fill me in on how to get values from a virtual joystick, using the standard joystick script, and apply it to a camera to allow the camera to freely orbit around a sphere’s surface?

Well, you don’t provide much detail - I’m not 100% sure what you’re after. But here’s a simple approach that might help:

  • In the editor, create an empty game object called “Pivot”

  • Make your camera a child of Pivot.

  • Move the camera away from Pivot, whatever distance you need.

  • Now attach a script to Pivot. Something like:

    public class RotateWithJoystick : MonoBehaviour {

     public Camera camera;
     
     void Update(){
     	//this will make the camera look "inwards" towards Pivot
     	camera.transform.LookAt(transform);
    
     	float speed = 10.0f;
     	transform.Rotate(Vector3.up, Input.GetAxis("horizontal") * speed);
     	transform.Rotate(Vector3.left, Input.GetAxis("vertical") * speed);
     }
    

    }

  • Assign your camera to the camera var in the script attached to Pivot

  • You’ll have to mess with the rotations (e.g., you might not want Vector3.up assigned to the horizontal axis, and speed might be wrong)

Hi, can I download this code in some way please?
camera.transform.LookAt(transform); should be there or not?