unity how to control camera view using a single joystick?

≯℡__Kan透↙ 提交于 2019-12-12 16:19:20

问题


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

回答1:


  • 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


来源:https://stackoverflow.com/questions/48294739/unity-how-to-control-camera-view-using-a-single-joystick

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!