GUI with drag being choppy

I seriously don’t know how to title this post but basically I was making this gui that has like drag(?)

I’ll just show with a video.

https://gyazo.com/cbca042e56deee1303ddde5bc245e072.mp4

The GUI has the drag effect but it’s kinda choppy, and I’m too desperate to find a solution or a better way to do it. Here’s my current code:

local cam = workspace.Camera
local frame = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("ScreenGui").Frame
local prev = CFrame.new(0, 0, 0)

game["Run Service"].RenderStepped:Connect(function(dt)
	workspace.Part.CFrame = cam.CFrame * CFrame.new(0, 0, -10)
	local view = workspace.Camera:WorldToScreenPoint(prev.Position)
	prev = workspace.Part.CFrame
	frame.Position = UDim2.fromOffset(view.X, view.Y)
end)

Any help would be greatly appreciated.

Why do you have prev? As far as I can see, it’s off by 1 render step because of it. prev gets set after WorldToScreenPoint gets assigned to view which is being used to position the frame.

prev is the Previous CFrame of the part, that what makes the drag effect possible.

Why don’t you take the current part CFrame and take WorldToScreenPoint with it? Is there a reason to use the previous CFrame of the part?

Yeah.. to make the gui have that drag effect? else it would be a static GUI.

Then I would use Heartbeat or BindToRenderStep to take previous CFrame. They are closer to RenderStepped than one more render step which shall be more precise.

1 Like

Yes, you should use either one of those, these should fire after physics calculations.
image

1 Like

I already had a feeling that this wouldn’t work but I tried it anyways incase I was wrong. Although the choppy-ness became less choppy but still didn’t fix it.

@PuppoJon

https://gyazo.com/ee11416747502a72363142392607f4d5

Update: I may be asking too much here, this is good enough for me. Thanks

1 Like

You could probably tween the position every frame. This works since tweens can override each other therefore it will tween faster as the desired distance is further.