- Home /
Joystick to movement and rotate camera same time
Hello,
I have a problem. I want to use joystick to movement player. I want to rotate camera if player click ANYWHERE ELSE on screen.
My problem: If the player use joystick then camera rotate too! I tried IsPointerOverGameObject not good, because player press the joystick and drag it to the screen then joystick still work, but camera rotate again :( So I think if player use joystick then I disable rotate camera, but not good, because If player use two fingers it is possible both at the same time. (one finger joystick and one finger screen)
public float speed = 2.0f;
private float X;
private float Y;
void Update() {
if (Input.GetMouseButton (0)) {
if(!EventSystem.current.IsPointerOverGameObject ()) {
transform.Rotate (new Vector3 (Input.GetAxis ("Mouse Y") * speed, -Input.GetAxis ("Mouse X") * speed, 0));
X = transform.rotation.eulerAngles.x;
Y = transform.rotation.eulerAngles.y;
transform.rotation = Quaternion.Euler (X, Y, 0);
}
}
}
So another solution is needed. If player use the joystick, do not move the camera. But if player use it with two fingers (one with the joystick and the other with the camera allowed!) I hope you understand. (similar to other shooting games).
Thanks!
personally, why bother with the mouse? I'd map a joystick key. You are also alittle confusing (sorry). What's with the mouse having to be over a gameobject?
if(mouse down) { camera.Rotate (new Vector3 (Input.GetAxis ("$$anonymous$$ouse Y") * speed, -Input.GetAxis ("$$anonymous$$ouse X") * speed, 0)); } if(joystick value != 0) { move player }
so breaking that down. if the mouse is being held down, roate the camera. then regardless of weither or not the mouse is being held, if the joystick is active then move the player