Kia Jun
Kia Jun

Reputation: 87

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);
}
}

Upvotes: 4

Views: 2036

Answers (1)

NoobProgrammer
NoobProgrammer

Reputation: 488

  • 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

Upvotes: 2

Related Questions