Roblox physics issue

Hello fellow developers! :wave:
Recently, I have been trying to calculate the time an object with a constant velocity needs to travel a linear path, using the velocity formula:

Anyways, I proceeded to make two parts

  • Part 1: Anchored (reach)
  • Part 2: Not anchored, has Linear Velocity (mover)

The ‘mover’ part with the velocity (blue arrow in image) should go toward the ‘reach’ part
NOTE: They both share the same axis, so the velocity direction is correct

Other properties for the LinearVelocity:

Now the real question is,
Why is the time calculated not accurate??

  • Here’s the code:
local mover = workspace.mover
local reach = workspace.reach

local dis = (mover.Position - reach.Position).Magnitude
local speed = mover.LinearVelocity.VectorVelocity.Magnitude

task.delay(dis/speed, function()
    print("reached")
end)
  • It would print ‘reached’ before it had actually reached, maybe at around 80% of the path
  • I was not able to figure out why this is happening, my calculations should be right

Things I have tried to fix the issue:

None of the above seemed to fix my issue,
If you can help, please do I really appreciate it :pray:

Thanks!

Do you think it could be because of friction? You can change friction, mass, etc in custom physical properties for the part.

I did disable those factors, but still same result

Hmm okay then. I have no clue.

Perhaps it is not an issue with roblox physics.

But with Roblox task scheduler instead since task.delay is in heartbeat which happens after rendering so you might need to wait the next frame for it to render reaching the goal.

Try adding an extra task.wait() to see if that solves anything.

https://create.roblox.com/docs/studio/microprofiler/task-scheduler

Reminds me of the .Touched problem as it usually triggers the frame before collision and not when the part is directly touching hence causing the part position to not directly be on the target collided part (more noticeable with really fast parts).

I also did think the issue came from the task scheduler itself,
I proceeded to add a task.wait() instead, still same results