- Home /
Rotate camera smoothly to certain degrees with iphone touch
I'm trying to emulate the "swipe to look" controls found in iPhone games such as Dead Trigger (made in Unity), Modern Combat and Minecraft, in that swiping your finger rotates the camera to your fingers' position, then stops. I've tried using both the mouselook script and various joysticks/joypads positioned in the center of the screen and set to invisible but none of them have the "stopping" affect (if you hold your finger down the camera will spin in circles until you let go). I therefore have two questions: 1) Are there any existing control mechanisms that emulate this style (I'm willing to pay) 2) If not, how would I go about achieving this effect? EDIT: I do not mean joystick controls. A joystick will rotate indefinitely in a certain direction until touch ends. These games rotate to a certain point then STOP, regardless of whether touch is maintained or not. The best way to experience this is to download "Minecraft Lite" or "Dead Trigger", both are free, but this mechanic seems to be fairly prevalent throughout iPhone FPSes. Others off the top of my head are the Gameloft games ie Modern Combat, Eden World Builder and Marathon. Here is a video of the dead trigger controls: https://www.youtube.com/watch?v=PRW01ygkmuE Eden Worldbuilder: http://www.youtube.com/watch?v=XaqGVfbB8B4
Given an identified touch, it seems to me that all they are doing is:
var yRotate = -touch.deltaPosition.x * factor / Screen.height;
var xRotate = touch.deltaPosition.y * factor / Screen.height;
transform.Rotate(xRotate, yRotate, 0.0);
The division by screen height is a basic way to making the movement somewhat consistent across different devices. They may be using Screen.dpi ins$$anonymous$$d.
But What if also want to restrict my angles to restrict ?????
Would someone be able to explain to explain this in a bit more detail please?
Thanks in advance.
Answer by robertbu · Aug 08, 2014 at 02:45 PM
But What if also want to restrict my angles to restrict ?????
Maintain your own class instance Vector3. Something like this:
private var angles : Vector3 = Vector3.zero;
Then the code would be:
angles.x += touch.deltaPosition.y * factor / Screen.height;
angles.y += -touch.deltaPosition.x * factor / Screen.height;
angles.x = Mathf.Clamp(angles.x, -45.0, 45.0);
transform.eulerAngles = angles;
The code clamps the 'x' rotation between -45 and 45 degrees.
Your answer
Follow this Question
Related Questions
2D Camera (Android, Iphone) 1 Answer
how to rotate 3d model in touch using guy texture object 1 Answer
rotate object to touch position 1 Answer
iphone camera rotation by touch 4 Answers