Physics formula calculation inconsistency / not being accurate

I am currently trying to calculate velocity accurately with real-world formulas. However, I found big chunks of difference between what I am trying to achieve.

Apologies for the lengthy explanation in advance, I am calculating velocity using:

d = .5 * g * t^2 -- distance
t = √(2h / g) -- time taken
v = g * t -- velocity

So in context it’ll look like:

var.elaspedTime += deltaTime -- variable table where i store default values
local gravity = workspace.Gravity -- 21/m^2 | 75
local distFallen = .5 * gravity * var.elaspedTime^2 -- d = .5 * g * t^2
local timeTaken = math.sqrt((2 * distFallen)/gravity) -- t = √(2h / g)
local velocity = gravity * timeTaken -- v = g * t

I expected this to work, so I tried it out and fall 10 studs down, but it returned 5.4930068155436 instead of anywhere remotely near to 10.

So I tried an alternative method I used previously which was subtracting the final Y position from the initial Y position to get the EXACT distance, it looks something like:

if hum:GetState() == Enum.HumanoidStateType.Freefall and rootpart.Velocity.Y < -.5 and not isGrounded() and not var.isFalling then
		var.isFalling = true
		local maxHeight = rootpart.Position.Y
		local maxVelo
		repeat
			maxVelo = math.abs(math.max(rootpart.Velocity.Y))
			runService.Heartbeat:Wait()
		until (hum:GetState() ~= Enum.HumanoidStateType.Freefall and hum:GetState() ~= Enum.HumanoidStateType.Jumping) or rootpart.Velocity.Y >= -.5
		local gravity = workspace.Gravity
		local distFallen = math.max(0, maxHeight - rootpart.CFrame.Y)
		local timeTaken = math.sqrt((2 * distFallen)/gravity) -- t = √(2h / g)
		local velocity = gravity * timeTaken -- v = g * t
		print("---- ACCURATE ----")
		print("Distance: " .. distFallen)
		print("Time: " .. timeTaken)
		print("Velocity: " .. velocity)
		print("Actual Velocity: " .. maxVelo)
		var.isFalling = false
	end
end

This returned an accurate result of 9.202651977539062, close to being a 10.

In summary, I am just confused as to why my formulas didn’t work as intended or what I have done wrong (unit conversion? wrong formula used?)

Here is a video example:


This is the output:
image

If anyone is good in math or physics please help me out :,) Thanks.

I am pretty sure the formulas for velocity, time and distance are these:

velocity= distance / timeTaken
distance = velocity * timeTaken
timetaken = distance / velocity

I think you are mistaking speed for velocity, they are not the same.

they still do take the same formula (as far as my knowledge)

I am finding the velocity of a falling object hence, I used V = gt

image

bumping this cos i still hv not clue

You’re supplying one value to math.max, which picks the highest number out of a list of numbers. Since you only provide one number, that will always be picked.

I am pretty sure this is because:

  1. The ROBLOX physics engine calculates things in frames, because of uncertainty of other forces, rather than planning any block’s location ahead of time. Because of this truncating (essentially, it is like rounding numbers every step of the way rather than at the end which can build up inaccuracy), values may get inaccurate over time.
  2. It could also be that the root part is moved around slightly while animating the end of the fall and beginning. I suspect a combination of the previous two things I mentioned.

It’s possible that the character controller messes with the physics, or that the state isn’t being changed at exactly the right time.

Your equations look correct, and I know you can calculate the exact trajectory of normal objects (ex: Modeling a projectile's motion).

Note you’re not using the initial velocity term in the distance change equation (the zero initial velocity assumption in this case is pretty good though).

Edit:

Screenshot 2024-02-27 at 9.46.37 PM

It looks like the not accurate one isn’t counting the time properly, which I think would explain the difference.