Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I measure the strength of a fall?

I have a ball hovering over a baseplate and when I release it I want to know how strong it hits the floor, but I don't know how to measure it correctly.

I've tried something with the Y axis velocity:

ball.Touched:connect(function(baseplate)
	print(ball.Velocity.Y)
end

It's quite simple, but doesn't work. The problem is that when it hits the baseplate, it bounces instantly and the printed result is small and positive. Maybe the Touched event is slower than the physics rendering, so that method is useless.

Any suggestion to help me?

1 answer

I'll attempt to make this for you, I'll have a loop that will record the Velocity, then It will stop looping when it touches a part.


#Final Product

local velocity,velocity2
local touched = false

function callback() --Do this after touched
	print(velocity)
end

script.Parent.Touched:connect(function(p)
	if p.Name == "BasePlate" then --when they touch the part named...
		touched = true
	end
end)

spawn(function() while wait() do velocity = velocity2 velocity2 = script.Parent.Velocity.Y if touched then break end end end)

Hope it helps! ######Tell me if there are any errors in the comments so I can help!

3 comments

0

Doesn't make sense.

0

I thought of something like a loop, but then I would have to make a separate script. Anyway, I didn't get what you did there in the last lines, could you explain?

0

He's basically using a while true do loop to update the variables "velocity" and "velocity2" every 1/30th of a second. When the object touches the baseplate, it'll set the variable "touched" to true, and that will in turn break the loop causing the velocity to no longer update. That way, the velocity variable will be what the velocity of the object was once it hit the baseplate

This discussion is preserved as it was. New answers, comments, and votes are closed.