- Home /
Camera rotate using two fingers - mobile c#
I have a script where i use the positions of two fingers, and their deltapositions, and then calculate angles using vector2.angle, and if it increases then rotate camera right, and decreases i rotate left. i got that part to work. but how do i accommodate for when the two fingers pass each other (and are on the same line when create angles relative to 0,0)? When they cross each other, the angle increases (and camera rotate in other direction).
here is my code snippet: (in update method attached to camera (which is parented to invis empty gameobject to be able to rotate around)
currentAngleBetweenTouches = Vector2.Angle(Input.GetTouch(0).position, Input.GetTouch(1).position);
prevAngleBetweenTouches = Vector2.Angle((Input.GetTouch(0).position - Input.GetTouch(0).deltaPosition), (Input.GetTouch(1).position - Input.GetTouch(1).deltaPosition));
if ((currentAngleBetweenTouches - prevAngleBetweenTouches) - 0.25 > 0) //DeltaAngle posative, rotating clockwise
{
mainCamera.transform.parent.transform.Rotate(new Vector3(0.0F,0.0F,-5.0F)); //why 5? How do i accommodate for actual angle ?
else if ((currentAngleBetweenTouches - prevAngleBetweenTouches) + 0.25 < 0) //DeltaAngle negative, rotating counter-clockwise
{
mainCamera.transform.parent.transform.Rotate(new Vector3(0.0F,0.0F,5.0F));
}
Your answer
Follow this Question
Related Questions
Make my camera turn smoothly 2 Answers
How to change first person controller input when passing through a collider? 1 Answer
Camera momentum after lifting finger 0 Answers
How to lock camera angle on key press? 1 Answer
Object rotates with camera 2 Answers