Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --returns unit vector n, the normal of the face of Part `part` which contains Vector3 `pos`
- local function GetNormal(part, pos)
- local abs = math.abs
- local shape = part:IsA("Part") and part.Shape.Value or part:IsA("WedgePart") and 3 or part:IsA("CornerWedgePart") and 4
- if shape == 0 or shape == 2 then
- return (pos-part.Position).unit
- elseif shape == 1 or shape == 3 then
- local vec = part.CFrame:pointToObjectSpace(pos)/part.Size
- local rot = part.CFrame-part.Position
- local x, y, z = vec.X, vec.Y, vec.Z
- if x > 0.499 then return rot * Vector3.new(1, 0, 0)
- elseif x < -0.499 then return rot * Vector3.new(-1, 0, 0)
- elseif shape == 1 and y > 0.499 then return rot * Vector3.new(0, 1, 0)
- elseif y < -0.499 then return rot * Vector3.new(0, -1, 0)
- elseif z > 0.499 then return rot * Vector3.new(0, 0, 1)
- elseif shape == 1 and z < 0.499 then return rot * Vector3.new(0, 0, -1)
- end
- return rot * Vector3.new(0, part.Size.Z, -part.Size.Y).unit
- elseif shape == 4 then
- local vec = part.CFrame:pointToObjectSpace(pos)/part.Size
- local rot = part.CFrame-part.Position
- local x, y, z = vec.X, vec.Y, vec.Z
- if x > 0.499 then return rot * Vector3.new(1, 0, 0)
- elseif y < -0.499 then return rot * Vector3.new(0, -1, 0)
- elseif z < -0.499 then return rot * Vector3.new(0, 0, -1)
- elseif vec.unit:Dot(Vector3.new(0.707106769, 0, 0.707106769)) > 0 then return rot * Vector3.new(0, part.Size.Z, part.Size.Y).unit
- end
- return rot * Vector3.new(-part.Size.Y, part.Size.X, 0).unit
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement