Getting CFrame Rotation from Raycast.Instance

Hi, how do i get the rotation of a part from raycast.Instance?
I’ve tried doing this then converting it to CFrame.Angles

if raycastResult then
            local oX = raycastResult.Instance.Orientation.X
            local oY = raycastResult.Instance.Orientation.Y
            local OZ = raycastResult.Instance.Orientation.Z
            local anglesCFrame = CFrame.Angles(math.rad(oY),math.rad(oX), math.rad(OZ))
            local part = game.ServerStorage.Ore:Clone()
            part.Parent = game.Workspace.Ores
            local newCFrame = CFrame.new(raycastResult.Position + Vector3.new(0,2.5,0))
            part:SetPrimaryPartCFrame(newCFrame * anglesCFrame)
            CollectionService:AddTag(part, "Ore")
            game.ServerStorage.TotalOres.Value += 1
        end

But when the part spawns, it comes up like this (sometimes)


It works fine on flat surfaces btw.
I’ve also tried .FromOrientation but that messed things up even more.

Are you trying to align the rock with the grass? Directly copying over the orientation of the ground to the rock won’t work because those are global rotations and depending on how the model was constructed it can have different results

oh yeah here’s a thread i found that probably addresses all of your questions

1 Like

Yeah, they are using the deprecated raycast, any idea how to do this with the new raycast? I know how to get the hitPos (raycastResult.Position) but i have no idea how to get hitNormal.

local rayResult = workspace:Raycast(origin, direction * length, params)
local pos = rayResult.Position and rayResult.Position or origin + direction * length
local normal = rayResult.Normal
1 Like