Casting a Ray with multiple Vectors?

Hi, I’m currently working on a 3D-BirdEyed style game.
One of the parts i’m currently working on includes changing the Camera if the Player is either behind a Part or if the Player is below a Part (Such as the roof of an interior) - Was wondering if this is doable through the use of a single ray instead of casting multiple rays?

    local Module =

    {RunService = game:GetService("RunService"),

    Camera = workspace:WaitForChild("Camera"),

    Player = game.Players.LocalPlayer,

    Offset =, 20, 20)}

    function Module.Load()

    Module.RunService:BindToRenderStep("Camera", Enum.RenderPriority.Camera.Value, onRenderStep)


    function onRenderStep()

    local Position = Module.Player.Character:WaitForChild("HumanoidRootPart").CFrame.p

    Module.Camera.CoordinateFrame = + Module.Offset, Position)

    local CameraRay =, Position +, 500, 500) * 500)

    local CameraHit, position = workspace:FindPartOnRayWithIgnoreList(CameraRay, {Module.Player.Character})

    if CameraHit then

    if CameraHit.Name == "Roof" then

    Module.Offset =, 10, 20)

    elseif CameraHit.Name == "Building" then

    Module.Offset =, 20, 5)



    Module.Offset =, 20, 20)



    return Module

A much better method for this than racycasting is to use is GetPartsObscuringTarget

You can use multiple vectors with this method (though I’m not too sure why you’d want to), and it will save you a lot of code.

Example of how you would hide parts blocking the character:

local obscuringParts = {}
local function onRenderStep()
	for i, v in pairs(obscuringParts) do
		v.LocalTransparencyModifier = 0	
	obscuringParts = workspace.CurrentCamera:GetPartsObscuringTarget({Player.Character.PrimaryPart.Position}, {Player.Character:GetChildren()})
	for i, v in pairs(obscuringParts) do
		v.LocalTransparencyModifier = 0.5

Thanks to @AyeeAndrxw for pointing out that LocalTransparencyModifier existed.


You should probably be using LocalTransparency for this, as it won’t affect the old transparency of a part.

1 Like

Thanks but this doesn’t help with the Player being inside the interior (As this is a separate “chunk” loaded)
This is how the Camera itself will function, however upon a ‘roof’ in the Y axis or a ‘building’ in the Z access it will adjust.

You can use this method to find your camera offset, instead of using multiple raycasts and if starement. Just iterate through all the parts obscuring the view and add an offset for each one.

1 Like

You are completely right. I didn’t even know that existed, thank you. I will edit this now.