So i’ve been looking ont he devforum, and i did find some things that would theoretically let me get that; however i either don’t really understand them, or i don’t need them that way,
how would i get a readable radian angle from a RaycastResult?
The angle of what…? Refraction?
The raycast will give you a Normal vector. This vector points away from the surface that the ray hit; it is the direction of the surface.
You also still have the original direction of the ray.
You can find the angle between these two directions. There are a lot of tutorials online for it, but here’s some code instead.
-- example values
local originalRayVector = Vector3.new(45, -12, 9) -- can be pretty much anything
local normalVector = Vector3.new(0, 1, 0) -- normal points up, so it likely hit the top of a baseplate or something
local angle = math.acos(originalRayVector.Unit:Dot(normalVector)) -- in radians
-
originalRayVector.Unit
Unit vector of original vector. A vector has a direction and length; this is like discarding the length information of the vector and keeping the direction, making the length exactly 1. -
:Dot()
Dot product. Look for an explanation elsewhere. Basically how far along each other the vectors lie. If the vectors are perpendicular, it’s 0; if the vectors are pointing the same direction, it’s the vectors’ magnitudes multiplied (which is 1 if both are direction-only/unit vectors) -
normalVector
No .Unit is needed for this one, because it’s already a direction -
math.acos()
Arc-cosine. Recall that cosine of 0 is 1, and indeed 0 degrees between the vectors means the dot product is nearly 1. And cosine of 90° is 0, so dot product is also 0
3 Likes
it’s giving me these vector forms, help?
wait, nevermind; i used math.deg() to find out if it’s correct; it is