I'm doing an airplane game and I want to be able to look to the sides of the cockpit. I want then that the user can press the center of the screen and slide the finger from left to right or viceversa and the camera will look into that direction.
How can I do this? I was thinking maybe using a sphere collider and detecting a raycast but since i only want to use horizontal movement i don't know if that's the best way to achieve it. Any ideas? Any easy script?
Hi, I have something you just have to set it up to work for your game
// If there is one touch on the device…
if(Input.touchCount == 1)
{
// Store touch.
Touch touchZero = Input.GetTouch(0);
// Find the position in the previous frame of touch.
Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition;
// Find the magnitude of the vector (the distance) between the touches in each frame.
Vector2 prevTouchDeltaMag = touchZeroPrevPos;
Vector2 touchDeltaMag = touchZero.position;
// Find the difference in the distances between each frame.
Vector2 deltaMagnitudeDiff = prevTouchDeltaMag - touchDeltaMag;
transform.RotateAround(Vector3.zero, transform.up, -deltaMagnitudeDiff.x * (dragSpeed / 400f));
transform.RotateAround(Vector3.zero, transform.right, deltaMagnitudeDiff.y * (dragSpeed / 400f));
}