Page 1 of 1

Breaking Joints

Posted: Fri Aug 09, 2013 4:53 am
by Molt
Is there any way in Chipmunk2D for Unity to find out how much force is applied onto a joint in order to see if it should break/be disabled?

I was experimenting with the engine and reached the point where I had the two sides of a trapdoor stable and held with a pivot, but couldn't see how to have the door fall open when hit with sufficient force without having it open at the slightest contact.

Re: Breaking Joints

Posted: Fri Aug 09, 2013 8:34 am
by slembcke
Oh shoot. Yes there is, and I forgot to expose it in the Unity binding. I just added it to the code and it will be in the next version.

In the meantime, you can add this to ChipmunkConstraint.cs:

Code: Select all

	/// Get the impulse applied by the constraint on the previous time step.
	/// Divide by Time.fixedDeltaTime to get the force.
	public float impulse {
		get { return (_handle != IntPtr.Zero ? CP._cpConstraintGetImpulse(_handle) : 0f); }
	}
Somebody else pointed out that I should implement proper breakable joints like Unity does, so I'll do that too. ;)