Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unity how to control camera view using a single joystick?

Does any one know how to control the camera view with only a single joystick? Currently im using a joystick from the switch. Heres my current code.

 public class MoveCamera : MonoBehaviour 
{
public float speed = 1.0f;
Camera cameraMovement;

void Update () 
{    

    float xRot = speed * Input.GetAxis("JoyStickX");
    float yRot = speed * Input.GetAxis("JoyStickY");

    transform.Rotate(xRot, yRot, 0.0f);
}
}
like image 902
Kia Jun Avatar asked Oct 24 '25 15:10

Kia Jun


1 Answers

  • 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 this :

 void Update(){
     float speed = 3.0f;
     float xRot = speed * Input.GetAxis("Vertical");
     float yRot = speed * Input.GetAxis("Horizontal");
     transform.Rotate(xRot, yRot, 0.0f);
  }
  • Assign your camera to the camera var in the script attached to Pivot
  • Now you do the messing around of the rotation
like image 160
NoobProgrammer Avatar answered Oct 26 '25 04:10

NoobProgrammer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!