armory/Sources/armory/logicnode/SetParentNode.hx
knowledgenude b178655487
Fix rigid bodies continuing to move when parented
This fixes one more bug from here: https://github.com/armory3d/armory/issues/1830

I don't know if this is a correct fix, but solved a problem for me.

One last bug that stills is the rigid body in "random" places when parented. To fix this, when the rigid body (no matter if active or passive) is parented, it must have Animated checkbox checked. I don't know how to do this. This will solve all problems related to it, except the "Keep Transform" unchecked one.
2020-09-04 20:50:46 -03:00

38 lines
904 B
Haxe

package armory.logicnode;
import iron.object.Object;
import armory.trait.physics.RigidBody;
class SetParentNode extends LogicNode {
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
var object: Object = inputs[1].get();
var parent: Object;
var isUnparent = false;
if (Std.is(inputs[2].node, ObjectNode)) {
var parentNode = cast(inputs[2].node, ObjectNode);
isUnparent = parentNode.objectName == "";
}
if (isUnparent) parent = iron.Scene.active.root;
else parent = inputs[2].get();
if (object == null || parent == null || object.parent == parent) return;
object.parent.removeChild(object, isUnparent); // keepTransform
#if arm_physics
var rigidBody = object.getTrait(RigidBody);
if (rigidBody != null) rigidBody.setActivationState(0);
#end
parent.addChild(object, !isUnparent); // applyInverse
runOutput(0);
}
}