Raycasting a visible point of view

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I am making a camera tool that uses ViewportFrame(s) to allow players in-game to take pictures but the picture can only be saved in that server. We will be using boatbomber’s ViewportFrame Handler module for rendering to make coding this easier and not creating a mess.

  2. What is the issue? Include screenshots / videos if possible!
    I have no experience in raycasting, I would like to raycast to the directions from left to right (basically any object visible to the camera) so that I can pass the objects to the ViewportFrame Handler module.


    Top of the picture is the front view, bottom is back view.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

  • Reading the Developer Hub but I couldn’t really understand the whole thing

From the image, Couldn’t you use Spatial Query API??

Spatial Query API? I don’t remember or I forgot so what’s that

Get part in box get part in part get part in radius

Ah okay, that’s very helpful, thanks for helping!

Rough code:

if workspace:FindFirstChild("Hitbox") then workspace:FindFirstChild("Hitbox"):Destroy() end
local head = workspace.Head
local hitbox = Instance.new("Part")
hitbox.Color = Color3.fromRGB(0, 255, 0)
hitbox.Transparency = 0.5
hitbox.Size = Vector3.new(100, 100, 100)
hitbox.Anchored = true
hitbox.CanCollide = false
hitbox.CanTouch = false
hitbox.CanQuery = false
hitbox.Name = "Hitbox"
hitbox.CFrame = head.CFrame:ToWorldSpace(CFrame.new(0, 0, -51))
hitbox.Parent = workspace
print(workspace:GetPartsInPart(hitbox))