How to break a pivot joint based on weights fell on it

i’m looking at bridge sample. instead of breaking joint when pressed/touched on a joint. i want to break joint when bridge no more able to bear the weight

do i need to loop through all the joints every second or so?
or is there a easy way for doing this

can anybody through some light on it? [import]uid: 97420 topic_id: 17420 reply_id: 317420[/import]

I have no experience with joints whatsoever (except for a sore knee), but what might work is to have
a function spawn a weight and increment a variable simultaneously.
[lua]local totalWeight = 0

local function spawn (e)
if e.phase == “ended” then
local weight1 = display.newImage(“anvil.png”)
totalWeight = totalWeight+10
end
end[/lua]
then you would remove a joint after totalWeight reaches desired amount:
[lua]local function break(e)
if totalWeight == 100 then
if specificJoint then
removeJoint end
end
end
Runtime:addEventListener(“enterFrame”, break)[/lua]
And that’s it. I don’t know if this will work, but it’s worth a shot.

Good luck,
J.K.
[import]uid: 66117 topic_id: 17420 reply_id: 65965[/import]

Thanks J.K for reply and your thought

it works if we have 1 or 2 joints
but if we have 10 joints or more

which joint we should break is the main question

and take care of your sore knee [import]uid: 97420 topic_id: 17420 reply_id: 65967[/import]

I would guess the one in the middle, considering that is where all the pressure is funneled to. [import]uid: 66117 topic_id: 17420 reply_id: 65969[/import]

Alright, I think I got It!!! Paste this at the top of the project:
[lua]local weight = 0
local breakable = true[/lua]
and place this after the breakJoint function:
[lua]local breakIt = function(e)
if breakable == true then
if weight == 100 then
joint[9]:removeSelf()
breakable = false
end
return true
end
end
Runtime:addEventListener(“enterFrame”, breakIt)[/lua]
that should work.

Good luck,
J.K. [import]uid: 66117 topic_id: 17420 reply_id: 65971[/import]

ya…

in this case you can’t break middle joint :slight_smile:
Just a case
[import]uid: 97420 topic_id: 17420 reply_id: 65973[/import]

so…
every time we have to check for weight at each joint

hmmmmm…

if we can specify some max limits for a joint and it breaks when it reached limit or some callback notification kind of thing would have made life little easier :slight_smile: [import]uid: 97420 topic_id: 17420 reply_id: 65974[/import]

Here are some modifications to make it break a random board:
[lua]local breakIt = function(e)
if breakable == true then
if weight == 100 then
joint[(math.random(2,15))]:removeSelf()
------------change ^ ^ to change the randomization
breakable = false
end
return true
end
end
Runtime:addEventListener(“enterFrame”, breakIt)[/lua]
Also, paste this to make removed weights not count toward the total weight:
[lua]ball.lb = 10
ball.lb = 20
weight = weight - t.lb
As far as the max limit per joint goes, is sounds like a good idea, but I haven’t the slightest clue how to do that.

P.S. don’t do math.random(1,16). if you use those values it won’t break. [import]uid: 66117 topic_id: 17420 reply_id: 65976[/import]