Placement system raycast distance from character instead of camera?

Hello, I need some help figuring out how to change the max distance a player can place an item to 25 studs from the character’s torso instead of 25 studs from the camera. Ideally, if there is a solution not using the legacy mouse as well that would be nice. Thanks!

https://gyazo.com/f772703b65302da429613559838ad736

local function MouseRaycast()
    local mousePosition = uis:GetMouseLocation()

    local mouseRay = camera:ViewportPointToRay(mousePosition.X, mousePosition.Y)

    local params = RaycastParams.new()
    params.FilterType = Enum.RaycastFilterType.Blacklist
    params.FilterDescendantsInstances = { script.Parent, game.Players.LocalPlayer.Character }

    local raycastResult = workspace:Raycast(mouseRay.Origin, mouseRay.Direction*25, params)

    return raycastResult
end```

Instead of making the ray a shorter length, i would check the distance from the ray.hit.position to the character humanoidrootpart.

If raycastresult and ( raycastresult.Position - character.HumanoidRootPart.Position ).Magnitude <= 25 then
 --code
End
1 Like