Doesnt follow camera correclty

How to make the part always in front and not like follow the sides

			local clone = v.Parent:Clone()
			clone.Parent = workspace.CurrentCamera
			clone.CanCollide = false
			clone:FindFirstChild("PointLight"):Destroy()
			
			local smoothSpeed = 0.4
			local offset = Vector3.new(0, -.75,-1.5)
			
			local targetCFrame = workspace.CurrentCamera.CFrame + (workspace.CurrentCamera.CFrame.Rotation * offset)
			clone.CFrame = targetCFrame
			
			game["Run Service"].RenderStepped:Connect(function(delta)
				
				local targetCFrame2 = workspace.CurrentCamera.CFrame + (workspace.CurrentCamera.CFrame.Rotation * offset)
				--clone.CFrame = clone.CFrame:Lerp(targetCFrame, smoothSpeed)
				clone.CFrame = targetCFrame2


			end)

I tested this with empty workspace

--!strict

local camera = assert(workspace.CurrentCamera)

local clone = workspace:WaitForChild("Part"):Clone() :: Part
clone.Parent = camera
clone.CanCollide = false
clone.Anchored = true

local offset = Vector3.new(0, -.75,-1.5)

game["Run Service"].RenderStepped:Connect(function(delta)

	local targetCFrame2 = camera.CFrame + (camera.CFrame.Rotation * offset)
	clone.CFrame = targetCFrame2

end)

and I don’t see the problem on the video.

Is lerp part intentionally commented out? if not and you using lerp in your video then you should use camera’s x and y position and lerp only the z axis of the item.

You should make it lerp by smoothSpeed*deltaTime
This keeps it framerate independant.

As for the plain cframe setting, I really don’t know because it works fine in a default baseplate. Check your microprofiler to see if there’s anything lagging Renderstepped.

Its intentionally commented out since I wanted to know If it was the lerp doing the problem

I think Its the RenderStepped lagging but I cannot seem to find out how to use the micro profiler

if thats the case, this will make your function run right after the camera.

Try this code I modified from RunService documentation;

local RunService = game:GetService("RunService")

local function afterCamera(delta)
 -- Code in here will run right after the default camera script 
end 

RunService:BindToRenderStep("After camera", Enum.RenderPriority.Camera.Value + 1, afterCamera) 

RunService | Documentation - Roblox Creator Hub

Ty! btw what is “BindToRenderStep” I saw this multiple times but I wasn’t sure on what It does

BindToRenderStep is a method that basically allows you when a function should be called during a frame’s phase that is right before the phase at which the frame would be rendered

to clarify in advance by “when a function should be called during a frame’s phase that is right before the phase at which the frame would be rendered”

im saying that during a standard .PreRender event, there is still like sub phases in that frame phase at which things are computed and calculated first and you can determine when that function in BindToRenderStep should be called in those sub phases using the second parameter in the method which it needs a number or enum given to it

then the properties in Enum.RenderPriority is the things you must provide to the method to determine when the function is called out of all of those sub phases

they are assigned to a number, which also explains why you can provide a raw number to second parameter instead of enum

1 Like

why not just use WeldConstraint? physics engine will correctly determine the phase the position is changed

set the thing CFrame in front of ur camera, and use weldconstraint to the thing and ur head for example

I might do this since I do not plan to make it lerp