I need to know on which surface/axis of the part a ray contacted with. Previously I used the surface normal and through some testing found the relationship between the surface and returned normal Vector. However when I tried the same thing with a rotated part, it no longer returns values between -1 and 1. What is the math to find the surface when it a part is rotated? RayCast is a basic raycasting function that returns that part hit, position of the hit, and the surface normal.
local hit,position,norm = RayCast(startPos,direction,tool.Parent) if hit then wait() print(norm) local x,y,z = norm.X, norm.Y, norm.Z if x ~= 0 and (y == 0 and z == 0) then hitx = true elseif y ~= 0 and (x == 0 and z == 0) then hity = true elseif z ~= 0 and (x == 0 and y == 0) then hitz = true end end
Since you're given a unit vector for a rotated part, it's easier to convert the given Vector3 to object coordinates. Then, your original comparison works fine:
local hit, position, norm = RayCast(startPos, direction, tool.Parent) if hit then wait() print(norm) norm = hit.CFrame:vectorToObjectSpace(norm) --This is where the magic happens. local x,y,z = norm.X, norm.Y, norm.Z if x ~= 0 and (y == 0 and z == 0) then hitx = true if x > 0 then print("Front") else print("Back") end elseif y ~= 0 and (x == 0 and z == 0) then hity = true if y > 0 then print("Top") else print("Bottom") end elseif z ~= 0 and (x == 0 and y == 0) then hitz = true if z > 0 then print("Left") --These two might be backwards! else print("Right") end end end