Commit 13ade2c7 authored by Viktor Lidholt's avatar Viktor Lidholt

Adds check for breaking forces in sprite physics joints

parent 90971695
......@@ -8,6 +8,7 @@ abstract class PhysicsJoint {
final PhysicsBody bodyA;
final PhysicsBody bodyB;
final double breakingForce;
bool _active = true;
box2d.Joint _joint;
......@@ -36,6 +37,25 @@ abstract class PhysicsJoint {
}
box2d.Joint _createB2Joint(PhysicsNode physicsNode);
void destroy() {
_detach();
}
void _checkBreakingForce(double dt) {
if (breakingForce == null) return;
if (_joint != null && _active) {
Vector2 reactionForce = new Vector2.zero();
_joint.getReactionForce(1.0 / dt, reactionForce);
if (breakingForce * breakingForce < reactionForce.length2) {
// TODO: Add callback
destroy();
}
}
}
}
class PhysicsJointRevolute extends PhysicsJoint {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment