Comments and answers for "Calculate launch angle based on launch direction"
http://answers.unity.com/questions/1633663/calculation-launch-angle-based-on-launch-direction.html
The latest comments and answers for the question "Calculate launch angle based on launch direction"Comment by Pangamini on Pangamini's comment
http://answers.unity.com/comments/1633867/view.html
Yeah, I am kind of happy that Unity didn't invent their own off-world math :DWed, 22 May 2019 09:12:17 GMTPangaminiComment by Bunny83 on Bunny83's comment
http://answers.unity.com/comments/1633862/view.html
Well, the white direction vector is just
Vector3 white = -HandlePosition;
The angle is just
float angle = Mathf.Atan2(white .y, white .x) * Mathf.Rad2Deg;
To make the range be 0 to 360 instead of -180 to 180 just do this afterwards:
if (angle < 0)
angle += 360;Wed, 22 May 2019 08:56:08 GMTBunny83Comment by Malyglut on Malyglut's comment
http://answers.unity.com/comments/1633701/view.html
Yes, you're completely right. I missed that.
Is what I'm doing right now a very hacky approach? If so, what would be the correct way of tackling the problem of calculating the angle between Blue and White?Tue, 21 May 2019 18:13:38 GMTMalyglutComment by Bunny83 on Bunny83's answer
http://answers.unity.com/comments/1633689/view.html
Note that adding 180° will not give you the angle between your white and blue vector when using the white direction vector but between your blue and black line. So you essentially use your "HandlePosition" which doesn't seem to be a position but a relative direction vector.
<br>
Since "White" is equal to `transform.position - HandlePosition.normalized` and your "newVector" is `transform.position - White` you just did calculate:
newVector = transform.position - (transform.position - HandlePosition.normalized)
This is the same as
newVector = HandlePosition.normalized
So you calculate the angle between the blue and black line and then add 180°. btw: Atan2 doesn't need a normalized vector.Tue, 21 May 2019 17:41:38 GMTBunny83Comment by Bunny83 on Bunny83's comment
http://answers.unity.com/comments/1633684/view.html
btw: [Atan2][1] is not specific to Unity. It exists in almost any math library. It just does arctan(y/x) and does a quadrant selection depending on the signs of x and y. It also handles problematic cases like the case when x == 0.
[1]: https://en.wikipedia.org/wiki/Atan2Tue, 21 May 2019 17:25:35 GMTBunny83Answer by Malyglut
http://answers.unity.com/answers/1633678/view.html
The solution was to calculate a new vector based on the White vector and then use it in the Mathf.Atan2 method.
Vector3 newVector = transform.position - White;
float angle = Mathf.Atan2(newVector.y, newVector.x) *Mathf.Rad2Deg;
This however gives values ranging from -180 to 180, to convert this to a 0 - 360 degree value I simply added 180 to the result of previous calculation.
angle+= 180;
This works nicely for what I'm trying to do.
Thanks to @Pangamini for guiding me in the right direction.Tue, 21 May 2019 17:09:42 GMTMalyglutComment by Pangamini on Pangamini's comment
http://answers.unity.com/comments/1633669/view.html
The vector that describes the directionTue, 21 May 2019 16:58:25 GMTPangaminiComment by Pangamini on Pangamini's comment
http://answers.unity.com/comments/1633667/view.html
"Return value is the angle between the x-axis and a 2D vector starting at zero and terminating at (x,y)."Tue, 21 May 2019 16:57:48 GMTPangaminiComment by Malyglut on Malyglut's answer
http://answers.unity.com/comments/1633665/view.html
Which vectors would I input into the Mathf.Atan2?Tue, 21 May 2019 16:53:07 GMTMalyglutAnswer by Pangamini
http://answers.unity.com/answers/1633664/view.html
Check out [Mathf.Atan2][1]
[1]: https://docs.unity3d.com/ScriptReference/Mathf.Atan2.htmlTue, 21 May 2019 16:51:11 GMTPangamini