I've written a script that:
- Detects the start and end position of a swipe gesture on the iPhone.
- Positions a game object at the midpoint of the start and end of the swipe.
- Resizes the game object based on the distance between the gesture points.
I'm having a lot of trouble determining the angle between the two gesture points and rotating the game object accordingly. I've included a sketch.!
You can compute the orientation using Atan2(), e.g. (untested C#-ish pseudocode):
Vector3 diff = p2 - p1;
float angle = Mathf.Atan2(diff.y, diff.x);
transform.rotation = Quaternion.Euler(0f, 0f, RadToDeg(angle));
Or by using Quaternion.LookRotation(), e.g.:
transform.rotation = Quaternion.LookRotation(p2 - p1, Vector3.forward);
saygon
3
I spend 2 days, tried own solutions and other posts from this forums, but this answer working for me.
Thanks a lot!