Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I measure the strength of a fall?

Asked by
Tesouro 407 Moderation Voter
8 years ago

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

Log in to vote
0
Answered by 8 years ago

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!
0
Doesn't make sense. Validark 1580 — 8y
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? Tesouro 407 — 8y
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 TurboFusion 1821 — 8y
Ad

Answer this question