What's wrong with my ledge climb system?

Hello!

I have spent a substantial amount of time on this issue and finally turned to the forum.

The issue is the climb is taking much longer than it should.

I’m making a ledge climbing system which uses linear interpolation for my game. It uses raycasts to determine initial and target positions, and plots 5 points which the character should move through. It then calculates a section of time, out of the total time the climb should take, and assigns it to this section of the climb. I’ve tested that bit and it all seems to work just fine.

At playtime of the “tween”, or Curve as my module calls it, too long seems to be spent on each section. I outputted how much time should be spent, and it’s fine. I outputted the step for the linear interpolation used, and it looks fine! I’ve definitely made a mistake of some kind along the way and I just can’t figure out where. I think it might be in the step calculation… somehow.

[Scripts hidden because solved]

I would recommend a RenderStepped function to do it since a normal loop might cause some issues in the Curve:Play() function.

--Right after you assign allocatedTime
local t = 0
		local connection
		connection = RunService.RenderStepped:Connect(function(deltaTime)
			t += deltaTime

			local alpha = ts:GetValue(t / allocatedTime, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)

			local newPosition = prevPos:Lerp(targetPos, alpha)

			hrp.CFrame = CFrame.new(newPosition) * CFrame.fromEulerAnglesXYZ(hrp.CFrame:ToEulerAnglesXYZ())

			if t >= allocatedTime then
				connection:Disconnect()
			end
		end)

		task.wait(allocatedTime)
1 Like

That will cause it to depend on frame rate, which is not ideal because it means it will take different times for different players. Also, since the connection will run in a different thread, I need to have a Boolean flag to indicate whether or not the next one should start. It’ll also add 5 threads to be garbage collected and I overall think it might be more difficult that way.

Since task.wait() also relies on framerate to determine duration passed, I don’t see the issues. Can you expand on what they might be?

(sorry if that came across as rude i didnt mean it to)

1 Like

Solved it myself after some adjustments.