- Home /
Degree from point?
I want to calculate the degree of a touch location away from the centre of my screen. Currently I have this code:
var myVector : Vector3; var myAngle : float;
function Update () {
if ( iPhoneInput.touchCount > 0 ){
for(var touch : iPhoneTouch in iPhoneInput.touches) {
myVector = new Vector3(240, 160, 0);
myAngle = Vector3.Angle(myVector, touch.position);
}
}
}
The problem is that it doesn't really work. The degree's it comes up with are wrong and even if you do a full 360 loop around the point it doesn't exceed 50 at any point, does anyone have any idea why?
Answer by Tetrad · Jul 11, 2010 at 08:01 PM
Daniel's answer is technically correct but will only give you 0-180 degrees.
If you want an angle that goes from -180-180 (i.e a full circle), you can use atan2
.
I.e.
var myAngle : float;
function Update () { var midScreenPoint = new Vector2 (Screen.width 0.5, Screen.height 0.5); var dir = Vector3.Normalize (Input.mousePosition - midScreenPoint); myAngle = Mathf.Atan2( dir.y, dir.x ); // myAngle is in radians }
Answer by Daniel 6 · Jul 11, 2010 at 05:52 PM
How's this work for you?
var myAngle : float;
function Update () { var midScreenPoint = new Vector2 (Screen.width 0.5, Screen.height 0.5); var dir = Vector3.Normalize (Input.mousePosition - midScreenPoint); myAngle = Vector3.Angle (Vector3.up, dir); }
Your answer
Follow this Question
Related Questions
Touches don't respond correct 2 Answers
iPhone - finger keeps touching screen 1 Answer
Multiple touch iPhone Buttons 0 Answers
How to display Swipe Marks on iPhone 1 Answer