Skip to content

Instantly share code, notes, and snippets.

@JohnBrookes
Created May 25, 2013 08:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JohnBrookes/6ceaa634c1afafce15ac to your computer and use it in GitHub Desktop.
Save JohnBrookes/6ceaa634c1afafce15ac to your computer and use it in GitHub Desktop.
Compound child Box collision
private function bodyCollisionAdded(e:AWPEvent):void {
if (AWPRigidBody(e.target).shape is AWPCollisionObject) {
for (var i:uint = 0; i < AWPCompoundShape(e.target.shape).children.length; i++) {
//Box collision
if (AWPCompoundShape(e.target.shape).children[i].shapeType == AWPCollisionShapeType.BOX_SHAPE) {
var mtx:Matrix3D = AWPCompoundShape(e.target.shape).getChildTransform(i).transform.clone();
mtx.invert();
var pos:Vector3D = mtx.transformVector(e.manifoldPoint.localPointA);
var d:Vector3D = AWPBoxShape(AWPCompoundShape(e.target.shape).children[i]).dimensions;
if (pos.x >= -d.x && pos.x <= d.x && pos.y >= -d.y && pos.y <= d.y && pos.z >= -d.z && pos.z <= d.z) {
trace(i + " Should be the index of the compound child");
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment