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

What is the appropriate equations for smashable glass?

Asked by
WVPII 5
9 years ago

So here is what I've stuck together, and has some ALRIGHT results, looking like this: https://gyazo.com/f7a370680579f3669a9522db4e2a6e1a

The bits in front are products of the script, and the bit behind is a replica of the part that was converted

local event = game.ReplicatedStorage.Remotes.Weapon.Smash

function event.OnServerInvoke(plr, objHit)
    --MATHS
    local size = objHit.Size
    local centerpos = objHit.Position
    local width = size.X / 3
    local hight = size.Y / 3
    local x1 = centerpos.X * 2
    local x2 = x1 / 3
    local y = centerpos.Y * 2
    local y2 = y / 3
    local position = Vector3.new(x2, y2, centerpos.Z)
    local sizenew = Vector3.new(width / 3, hight / 3, size.Z)
    local positions = {{position.X, position.Y, position.Z}, {position.X + width, position.Y, position.Z}, {position.X + (width * 2), position.Y, position.Z}--//Firstline--//
                    , {position.X, position.Y - hight, position.Z}, {position.X +  width, position.Y - hight, position.Z}, {position.X + (width * 2), position.Y - hight, position.Z},--//Secondline--//
                      {position.X, position.Y - (hight*2), position.Z}, {position.X +  width, position.Y - (hight*2), position.Z}, {position.X + (width * 2), position.Y - (hight*2), position.Z}}--//Thirdline//--
    --Generate
    objHit.CanCollide = false
    local i = 1
    while i <= 9 do
        local pos = positions[i]
        local shard = Instance.new("Part", workspace)
        shard.Transparency = objHit.Transparency
        shard.Reflectance = objHit.Transparency
        shard.Anchored = false
        shard.CanCollide = true
        shard.FormFactor = Enum.FormFactor.Custom
        shard.Name = "Glass"
        shard.Position = Vector3.new(pos[1], pos[2], pos[3])
        shard.Size = sizenew
        shard.Anchored = true
        i = i + 1
    end
    objHit.Transparency = 1



end

2 answers

Log in to vote
0
Answered by 9 years ago
local event = game.ReplicatedStorage.Remotes.Weapon.Smash

function event.OnServerInvoke(plr, objHit)
    --MATHS
    local size = objHit.Size
    local originalpos = objHit.Position
    local orix = size.X
    local oriy = size.Y
    local oriz = size.Z
    local x = orix / 3
    local y = oriy / 3
    local z = oriz
    local x1 = originalpos.X
    local x2 = x1 - x
    local y1 = originalpos.Y
    local y2 = y1 - y
    local z1 = originalpos.Z
    local positions = {
        Vector3.new(x2, y2, z1), Vector3.new(x2 + x, y2, z1), Vector3.new(x2 + (2 * x), y2, z1),
        Vector3.new(x2, y1, z1), Vector3.new(x2 + x, y1, z1), Vector3.new(x2 + (2 * x), y1, z1),
        Vector3.new(x2, y1 + y, z1), Vector3.new(x2 + x, y1 + y, z1), Vector3.new(x2 + (2 * x), y1 + y, z1),
    }
    local i = 1
    while i <= 9 do
        wait()
        local Part = Instance.new('Part', game.Workspace)
        Part.Anchored = true
        Part.Position = positions[i]
        Part.CanCollide = false
        Part.BrickColor = BrickColor.new'Teal'
        Part.Transparency = 0.7
        Part.Size = Vector3.new(x, y, z)
        i = i + 1
    end
end

x1 and y1 represent the center and since it is a 3 by 3 you do some algebra to get this

Ad
Log in to vote
0
Answered by 9 years ago

There's a smashable glass thing as a model in the toolbox, probably some kind of formula in there

Answer this question