How to put a Part CurrentCamera?

Hello, is it possible to recreate this effect? I don’t want to mimic the whole effect. I know that @boatbomber and @Isosta (please see the two videos below or click on the links) put a part in a camera and played around with the particle emitters. My question is: how can I put a part in a camera like the title of the topic says?

BoatBomber

Screen Distortion Rain

Isosta

(Open Source) ActiveVignette system using Particles

3 Likes

Putting parts in the current camera isn’t so necessary anymore with local parts being as easy to create as having a local script make them in a FilteringEnabled game.

Way back when the only way to create local parts was a local script putting them in a non-replicated location such as the camera. To answer your question, putting something in the local camera is as easy as:

part.Parent = game.Workspace.CurrentCamera

It’s important to note only local scripts can do this as the camera is non-replicated. This also won’t attach things to the camera, as parenting doesn’t influence position/cframe. Instead each frame you need to update the position of the parts CFrame to an object space around the camera before the frame is rendered.

2 Likes

Kan i weld the part with the current camera and why only local parts?

Only a local script can access the camera because that camera doesn’t exist on the server. Welds can’t be attached to Camera’s because cameras are not BaseParts. Camera’s don’t physically exist in the world, they are simply a point and settings at which the game renders the viewport from.

You would need to update the parts position, relative to the camera (this is called Object Space, as opposed to World Space) every frame to ensure the parts stay “attached” to the camera.

1 Like

Here’s an example script that will keep a Part's CFrame constant relative to the Camera:

local part = game.Workspace.PartA -- set to some part or other
local camera = game.Workspace.CurrentCamera

local cframeOffset = CFrame.new(0, 0, -5) -- Z component of offset must be < 0.5. Experiment with different values

game:GetService("RunService").RenderStepped:Connect(function()
	part.CFrame = camera.CFrame:ToWorldSpace(cframeOffset)
end)
6 Likes