Add "Has contact (Array)" node

This node was requested on issue #1256.
This commit is contained in:
Daniel B. Bruno 2020-04-11 17:57:21 -03:00
parent 0e77094a71
commit 4a3d3a58d6
2 changed files with 52 additions and 0 deletions

View file

@ -0,0 +1,35 @@
package armory.logicnode;
import iron.object.Object;
import armory.trait.physics.RigidBody;
class HasContactArrayNode extends LogicNode {
public function new(tree: LogicTree) {
super(tree);
}
override function get(from: Int): Dynamic {
var object1: Object = inputs[0].get();
var objects: Array<Object> = inputs[1].get();
if (object1 == null || objects == null) return false;
#if arm_physics
var physics = armory.trait.physics.PhysicsWorld.active;
var rb1 = object1.getTrait(RigidBody);
var rbs = physics.getContacts(rb1);
if (rb1 != null && rbs != null) {
for (object2 in objects) {
var rb2 = object2.getTrait(RigidBody);
for (rb in rbs) {
if (rb == rb2) {
return true;
}
}
}
}
#end
return false;
}
}

View file

@ -0,0 +1,17 @@
import bpy
from bpy.props import *
from bpy.types import Node, NodeSocket
from arm.logicnode.arm_nodes import *
class HasContactArrayNode(Node, ArmLogicTreeNode):
'''Has contact array node'''
bl_idname = 'LNHasContactArrayNode'
bl_label = 'Has Contact (Array)'
bl_icon = 'QUESTION'
def init(self, context):
self.inputs.new('ArmNodeSocketObject', 'Object 1')
self.inputs.new('ArmNodeSocketArray', 'Objects')
self.outputs.new('NodeSocketBool', 'Bool')
add_node(HasContactArrayNode, category='Physics')