How can I raycast to the mass of an object and not to the center of the object?

I’m trying to figure out how to raycast with this script

local origin = head.Position
			local direction = (grabpart.Position - origin).Unit * 10
			
			local result = workspace:Raycast(origin, direction)

but the result I have is that the raycast will always go to the center of the part

incorrect

and what I need is for it to detect the center of the face but in a single position like this

or basically something like the script above but instead of the raycast going to the center it goes to the position closest to the mass of the part

1 Like

I don’t necessarily understand what you’re trying to go for here. Are you trying to raycast with a centered vertical axis relative to the face but not horizontally?

I’m trying to cast like the type of ray cast that is used for script guns but when I do that with a part the raycast would go towards the center of the part and I don’t need that, I need it to detect the mass and not the center of the part part

Are you trying to aim for the center of mass? I’m confused.

Are you trying to raycast from a part face? Or are you trying to raycast to a part face?

I mean use the kind of raycast that no matter what direction your character goes, the raycast will always point to a part but I need it not to point to the center of that part.

So you want it to point to a part regardless of part orientation but not to the center?

yeah that’s what I need because I’m trying to make a ledge grab system and I think it would be a good start for me with the type of raycast I’m needing

Well, where else do you want the raycast to point to? An edge or a vertex?

just the faces of the part —“i need to fill the 30 letters to can reply”

local Face = "Front"
local function GetFacePosition(part: BasePart, face: Enum.NormalId)
    if ((typeof(part) == "Instance" and part:IsA("BasePart")) and (typeof(face) == "EnumItem" and face.EnumType == Enum.NormalId)) then
        return part.Position + ((part.Size/2) * Vector3.FromNormalId(face))
    end
end

-- GetFacePosition(workspace.Part, Enum.NormalId[Face])

Replace grabpart.Position in your raycast function with the output of GetFacePosition.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.