How to make ball movement smooth on all fps?

I’m using AlignPosition w/ 2 Attachments, 1 on the client-sided ball and the other iterating through a curve. My problem is that the movement is only smooth when on 60 fps, I was previously using a for loop and tried switching to runservice for deltaTime but that didn’t work.

Script:
(Commented Out are the two loops I tried)

local function PingPongVelocity(Ball, Time, SFX, P2)
	--print("Start Velocity")
	Ball.Anchored = false

	local newVelocity = Ball:FindFirstChild("AlignPosition")
	local BallAttachment = Ball:FindFirstChild("Att1")

	local startTime = time()

	local steps = 10
	local speed = game.Workspace.ServerBalls:FindFirstChild(Ball.Name).Speed.Value
	local duration = (Time - .25)
	local delayPerStep = duration / steps
	
	--for i = 1, steps do
	--	newVelocity.Attachment1 = folder["Part"..i]:FindFirstChild("Attachment")
	--	task.wait(delayPerStep)
	--end
	
	--local i = 1
	--local conn
	--conn = RunService.RenderStepped:Connect(function(dt)
	--	if i == steps then
	--		conn:Disconnect()
	--	end
	--	newVelocity.Attachment1 = folder["Part"..i]:FindFirstChild("Attachment")
	--	i = i + 1
	--	task.wait(delayPerStep * (dt*60))
	--end)
	
	
	local VFX = script.Attachment:Clone()
	VFX.Parent = game.Workspace
	VFX.Position = P2
	VFX["Whole swirl"]:Emit()
	game.Debris:AddItem(VFX, 1)

	--print("TIME: " .. time() - startTime)
	if SFX then
		local sound = game.Workspace["Ping pong sound effect"]:Clone()
		sound.Parent = Ball
		sound:Play()
		game.Debris:AddItem(sound, .5)
	else
		local sound = game.Workspace["ping pong hit sound"]:Clone()
		sound.Parent = Ball
		sound:Play()
		game.Debris:AddItem(sound, .5)
	end
	--Ball.Anchored = true

end

240 FPS V. 60 FPS

1 Like

looks great bro. i didnt see any difference between the 240 fps and 60.

I don’t think the video shows the 240 fps long enough but it’s noticeable snappier as it doesn’t follow the curves oppose to 60 fps

Longer 240 FPS Video:

Decided to just use a bezier tween module which actually solves another problem of the ball looking wonky at high speeds.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.