Smoothening object movement

Hi, so for my game, there’s object movement mechanics. Basically, when the player goes up to an object and continues to move in that direction, the object will push in the direction the player is going.

I’ve used CFrame for this, as it was the most reliable method I found, because I needed to use Region3s to determine if there would be any object collisions if the player were to push that object.

The only caveat, is that this creates a lot of stutter almost, it isn’t perfectly smooth. I’ve tried stuff like tweening or animating it to smoothly reach the end goal, but that really didn’t work out and it caused some delay issues.

I’ve tried welding the object to the player, and that worked really really well. However, sometimes the object would rotate a few degrees in some direction and for the type of game I’m working on, I can’t have that happen at all.

One idea I was thinking of was, in like a RenderStepped event or something, to see if the player is looking at an object and if so, attach the object by CFraming the object in front of the player every frame for as long as they’re pushing the object. This was probably one of the closest ideas I’ve had, but I can’t seem to figure out how to come up with a CFrame to set to the object.

Basically the problem I’m having, is I want the object to remain in whatever position that it’s in when the player gets close enough to it, but I also want this object to start moving with the player, based on the position of something like the HumanoidRootPart so the object moves smoothly, not instantly, if that makes any sense at all.

I can clarify if needed, but this is an overview of what I’ve been trying to achieve, and I really feel like that last solution has potential, but I just can’t figure out how to come up with the right offset to use, so the object keeps its starting position, but also moves with the player’s movement.

Thanks so much for reading this long and wordy post. :slight_smile:

1 Like

you basically got 2 options: use a body mover like align position and set the cframe to that or do smth like this

game:GetService("RunService").RenderStepped:Connect(function(dt)
  object.CFrame = cframe * dt
end)
1 Like

Thanks for the reply!

Do you know if AlignPosition could work for anchored objects? Because all the game objects’ parts are welded to an anchored root part in each model. Not exactly sure how I could implement that idea

iirc it only works for physically based (unanchored) parts but what I showed is basically what roblox does except instead of doing that they use the objects velocity to predict where it will be in the next frame then interpolate it to that using the delta time as some sort of modifier

1 Like

that’s a cool idea, but i’m not that smart haha

thanks though

watch put this vs this in baseplate

local pos = Vector3.new(0,0,0)
local part = Instance.new("Part")
part.Anchored = true
part.Parent = workspace
local scalar = 5
while wait() do
  pos = Vector3.new(sin(os.clock()) * scalar, scalar, cos(os.clock()) * scalar)
   part.CFrame = CFrame.new(pos, Vector3.new(0,0,0))
end
local pos = Vector3.new(0,0,0)
local part = Instance.new("Part")
part.Anchored = true
part.Parent = workspace
local scalar = 5
game:GetService("RunService").RenderStepped:Connect(function(dt)
  pos = Vector3.new(sin(os.clock()) * scalar, scalar, cos(os.clock()) * scalar)
  part.CFrame = CFrame.new(pos, Vector3.new(0,0,0)) * dt
end)
1 Like