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

Dividing an object's volume by .2^3?

Asked by 10 years ago
local b = .2 * .2 * .2

script.Parent.Touched:connect(function(hit)
    if hit.Name == "Scrap" and not hit.Size == Vector3.new(.2, .2, .2) then
        hitmass = hit.Size.X * hit.Size.Y * hit.Size.Z
        a = hitmass / b
        for i = 1, tonumber(a) do
            dust = Instance.new("Part", game.Workspace)
            dust.Size = Vector3.new(.2, .2, .2)
            dust.Position = hit.Position
            dust.BrickColor = hit.BrickColor
        end
        hit:Destroy()
    end
end)

I'm confused. I've never done this much math in Lua. No output.

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

tonumber is not necessary in this case. a is already a number.

hitmass is being computed correctly, but just to let you know, GetMass actually is a property of parts (although I suppose the density of parts with materials may be subject to change, so your volume approach is just fine too!)

Parts by default do not have a FormFactor of Custom, so they will reject the size Vector3.new(0.2,0.2,0.2). You need to set the FormFactor to Custom before setting the size to that.

Everything else is fine, perhaps not quite what you're looking for, because all of the parts will be smashed together in the center of the part.

A separate warning: 0.2 cannot be losslessly stored in binary. This means that there is a chance that Vector3.new(.2,.2,.2) may not be equal to an apparently equal vector. While it will probably be okay, it's better to allow very small tolerances (but obviously more complicated).

In this particular case, it would probably be better to reference the object's length or volume instead, anyway, which would be safer, and, for instance, not break extremely tiny (or smaller dust) up more: hit.Size.magnitude < 0.35

Ad

Answer this question