Stepped weirdness

I am not sure if this is a issue with me updating each step or if i should be using a body mover instead like align position or whateves. However this is the weird stuff i get with my current code

local holding = false
local object = nil
local mouse = game.Players.LocalPlayer:GetMouse()
mouse.Button1Down:Connect(function()
	if not holding then
		object = workspace.Objects:GetChildren()[math.random(1, #workspace.Objects:GetChildren())]
	end
	holding = true
end)
mouse.Button1Up:Connect(function()
	holding = false
	object = nil
end)
game:GetService("RunService").Stepped:Connect(function(dt)
	if object then
		object.Position = workspace.CurrentCamera.CFrame.Position + (mouse.UnitRay.Direction * 20)
	end
end)

EDIT: It was totally due to stepped

Does it work better with Heartbeat?

Heartbeat fires after physics is processed, Stepped fires before I think.

The problem is probably the part isn’t anchored. Because it’s not anchored, gravity is kicking in and adding to velocity. Because the physics engine runs at a faster frequency than rendering, you end up having the part drop from the given position due to the built-up velocity.

That’s my guess at least.

You could fix it by anchoring it. It would be better though to use a body mover to hold the position.

1 Like

Heartbeat gave the same effect as what i was using before, renderstepped. Is there a specific difference between the two?


From here.

The movement of unanchored parts happens between the Stepped and Heartbeat events, so when using a RunService event you should choose the one that makes the most sense with what you are trying to achieve.

But the issue may just be with the part being unanchored, since that internal update can happen multiple times in a rendering frame, as @sleitnick said.

A possible solution could be to switch to bodymovers, or anchor the part temporarily while it is being picked up and moved.

Stepped returns currentTime and deltaTime RunService.Stepped (roblox.com). So you’re multiplying by the total time the service has been running, and not the time passed between frames.