Hello all,
I'm currently experiencing the situation where my joints break apart. I'm trying to simulate a chain using the RevoluteJoint.
I had it understood that once you join two bodies, in order for them to separate you have to do it manually. Has anyone experienced
the situation before?
Any suggestions as to what the problem may be would be great.
-r
Prevent joints from breaking.
Re: Prevent joints from breaking.
Oh, that's pretty bad. I'm afraid you have to go see a doctor. sorry, I had tornodal wrote:Hello all,
I'm currently experiencing the situation where my joints break apart.
Seriously though, what do you mean by breaking apart? Do the links break apart completely, and start behaving like there was no joint at all, or the joints just "stretch" under a load?
Re: Prevent joints from breaking.
The first case. The bodies start to behave as if they were not connected at all.
I think I may have fixed it but I'm not sure.
Here is the old code:
Code: Select all
local centerx, centery = link:getBody():getWorldCenter()
joint = love.physics.newRevoluteJoint(link:getBody(), lastLink:getBody(), centerx - (width * 0.5), centery)
joint:setCollideConnected(true)
Code: Select all
local centerx, centery = link:getBody():getWorldCenter()
joint = love.physics.newRevoluteJoint(link:getBody(), lastLink:getBody(), centerx - (width * 0.5), centery)
joint:setCollideConnected(true)
table.insert(chain.joints, joint)
I'm not 100% sure to be honest. Any more input would be great.
-r
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Prevent joints from breaking.
joint seems to be a global, so if you run this multiple times it gets overwritten. This, in turn, means that there is no longer a reference to the joint and it will, at some point, get garbage collected, meaning it will be removed from the simulation as well.
Re: Prevent joints from breaking.
Thank you for answering.
A little bit before the loop I have:
I'm sorry for omitting the piece of information.
Thank.
-r
A little bit before the loop I have:
Code: Select all
local joint = 0
Thank.
-r
Re: Prevent joints from breaking.
You're probably correct. If you don't store the references to physics objects somewhere, they will get destroyed when Lua garbage-collects them - it's not enough to have them inside a world to prevent this. Your change should be enough to fix it if you don't discard the 'chain' table afterwards.rnodal wrote:It seems that lua was doing some garbage collection and maybe that was causing the joints to get destroyed?
Re: Prevent joints from breaking.
So far so good with the change I made.
Thank you all for taking the time to help me.
-r
Thank you all for taking the time to help me.
-r
Who is online
Users browsing this forum: No registered users and 4 guests