Attach a part to client camera

Is there any way to weld/attach a block to the playercamera, so that as the camera moves around the block stays in the same position on a client’s screen? I’ve attempted this by updating the CFrame of the block if the camera position changes (a lot of stutter there) and I’ve tried using TweenService on the block (see video below.)

Neither method produces the desired results of making it look like the block is “attached” to the screen. Anyone have any tips/things to try? Thanks

2 Likes

You can set the CFrame of the part using BindToRenderStep with priority.

You can use BindToRenderStep() and set the priortiy to Enum.RenderPriority.Camera.Value.
Here is more info.

local runservice = game:GetService("RunService")
local part = --wherever it is

local function SetToCamera()
    part.CFrame = workspace.CurrentCamera.CFrame
end

runservice:BindToRenderStep("Any name you want", Enum.RenderPriority.Camera.Value, SetToCFrame())

Set the CFrame of the part to the camera’s CFrame. If you want like a quint tween, then make it do it every .1 seconds, and have the quint tween take around .2 - .5 seconds.

1 Like

Updating the CFrame of the part every time the Camera’s CFrame changes works fine for me?

local Camera = workspace.CurrentCamera
local part = Instance.new"Part"
part.CanCollide = false
part.Anchored = true
part.Parent = workspace
local function update()
	part.CFrame = Camera.CFrame*CFrame.new(0,0,-5)*CFrame.Angles(math.pi/7,math.pi/9,math.pi/2)
end
Camera:GetPropertyChangedSignal"CFrame":Connect(update)
update()

https://i.gyazo.com/1103e8845c284ec240e5ba302ae19b3c.mp4

5 Likes

This works great, thanks :slight_smile: I realize now the way I was trying to achieve it earlier (with an infinite while loop which updated the position) was probably not only inefficient but quite ineffective compared to this method. Thank you again

1 Like

Hey do you know how I can make the part an already existing part instead of a new part? Because every time I set it to that part it says it’s not a valid child of Workspace.

Where is is parented? I have mine in replicated storage and I cloned it and don’t forget to set the parent to workspace and it works perfectly fine.