❔ How can i calculate a rotation float from a direction vector?
i know this might not be the correct place to ask such a question, but i figured such a large number of capable minds, surely there is someone who can explain it to me :>
anyway, as i said in the title, i want to calculate a rotation based on a directional vector. i suck at math, and i cant find my answer on google, so im trying this place >.<
thanks in advance <3
10 Replies
I think it's
atan2(y, x)
...?yes vector2
ill try...
thinker227#5176
REPL Result: Success
Result: float
Compile: 470.228ms | Execution: 24.693ms | React with ❌ to remove this embed.
thinker227#5176
REPL Result: Success
Result: double
Compile: 409.332ms | Execution: 23.956ms | React with ❌ to remove this embed.
yeah it's atan2
given this is in radians
that'll work too
i dont understand >.<
i feel stupid
my math ain't mathing
https://www.mathsisfun.com/geometry/unit-circle.html
you need to know this
Trigonometric functions
In mathematics, the trigonometric functions (also called circular functions, angle functions or goniometric functions) are real functions which relate an angle of a right-angled triangle to ratios of two side lengths. They are widely used in all sciences that are related to geometry, such as navigation, solid mechanics, celestial mechanics, geod...
For a triangle with sides a b c where c is the hypotenuse and an angle o between a and c,
tan(o) = a / b
, and arctan
or the inverse of tan
takes the ratio a / b
and returns the angle o
: arctan(a / b) = o
So for a 2D vector, the angle of the vector is atan(vec.y / vec.x)
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.