- Home /
iphone camera rotation by touch
Hi
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?
I found the $$anonymous$$ouseOrbit script on the standard asseets and the wiki but it has a bug. too understand what i mean, get your target and turn it around to the left 140 degrees for instance. Now just 'click' the mouse but don't move it. If everything is correct, no camera orbit should happen since you are not moving the mouse. You will see this is not the case, the camera will rotate to some other default position.
Answer by goodhustle · Sep 25, 2010 at 11:27 PM
Hmm, the first thing I would try is to use touch deltaPosition to modify the camera's localEulerAngles.z property.
nope, that doesn't do it. I found the Orbit script on the wiki and standard assets but it has a bug: too understand what i mean, get your target and turn it around to the left 140 degrees for instance. Now just 'click' the mouse but don't move it. If everything is correct, no camera orbit should happen since you are not moving the mouse. You will see this is not the case, the camera will rotate to some other default position.
Answer by Brettman · Dec 18, 2010 at 09:40 PM
Were you able to figure this out? I'm banging my head right now trying to get it working. Thanks.
no luck. I tried every possible combination without success. If you manage to figure it out please let me know because it's very important for my game :/
Answer by Chakroun Yesser · Feb 23, 2011 at 12:14 AM
Hey Guys have you found any think about this??? :(
Answer by Sky2oxid · Jul 25, 2014 at 12:15 AM
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));
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613073905im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
2D Camera (Android, Iphone) 1 Answer
touch to move camera, scroll over level 1 Answer
How do you map touch points to world space? 1 Answer
Camera orbit with touch 1 Answer
Rotate camera smoothly to certain degrees with iphone touch 2 Answers