package leenkx.logicnode; import iron.object.Object; #if lnx_physics import leenkx.trait.physics.PhysicsCache; import leenkx.trait.physics.RigidBody; #end class OnContactNode extends LogicNode { public var property0: String; var lastContact = false; public function new(tree: LogicTree) { super(tree); tree.notifyOnFixedUpdate(fixedUpdate); } function fixedUpdate() { var object1: Object = inputs[0].get(); var object2: Object = inputs[1].get(); if (object1 == null) object1 = tree.object; if (object2 == null) object2 = tree.object; var contact = false; #if lnx_physics var rb1 = PhysicsCache.getCachedRigidBody(object1); var rb2 = PhysicsCache.getCachedRigidBody(object2); if (rb1 != null && rb2 != null) { var rbs = PhysicsCache.getCachedContacts(rb1); contact = PhysicsCache.hasContactWith(rbs, rb2); } #end var b = false; switch (property0) { case "begin": b = contact && !lastContact; case "overlap": b = contact; case "end": b = !contact && lastContact; } lastContact = contact; if (b) runOutput(0); } }