Objects Break Particle Trigger LUA

Published on ● Video Link: https://www.youtube.com/watch?v=wiyW0yRjGNE



Duration: 0:26
249 views
3


Thank you to @TonyCartony for answering some of my questions.

He gave me a LUA script that basically called me a "BUM!" when a beam breaks. After a few hours I was able to change the LUA to spawn particles when breaking.

LUA from Tony...

local M = {}

local wantedBeam = -1

local function onReset()
wantedBeam = -1

for _, beam in pairs(v.data.beams) do
if v.data.nodes[beam.id1].name == "a0" and v.data.nodes[beam.id2].name == "nl0" then
print("wanted beam found " .. tostring(beam.cid))
wantedBeam = beam.cid
end
end


end

local function updateGFX(dt)

for _, beam in pairs(v.data.beams) do
local beamBroken = obj:beamIsBroken(beam.cid)
if beamBroken and beam.cid == wantedBeam then
print("BUM!")
end
end

end



M.onReset = onReset
M.updateGFX = updateGFX


return M


My modification............

local M = {}

local wantedBeam = -1
local a0


local function onReset()
wantedBeam = -1

for _, beam in pairs(v.data.beams) do
if v.data.nodes[beam.id1].name == "a0" and v.data.nodes[beam.id2].name == "b4" then
print("wanted beam found " .. tostring(beam.cid))
wantedBeam = beam.cid
end
end


end

local function updateGFX(dt)

for _, beam in pairs(v.data.beams) do
local beamBroken = obj:beamIsBroken(beam.cid)
if beamBroken and beam.cid == wantedBeam then
obj:addParticleByNodesRelative(0, 0, 25, 13, 0.01, 15)

end

end

end



M.onReset = onReset
M.updateGFX = updateGFX


return M

This was one of those days I was really feeling great figuring something out!
Not all days are good days of course... Enjoy the good ones when they happen. Haha, I was so happy I remade the song Particle Man by They Might Be Giants :)