armory/Sources/armory/logicnode/ApplyTorqueImpulseNode.hx

32 lines
705 B
Haxe
Raw Permalink Normal View History

2018-11-12 21:06:12 +01:00
package armory.logicnode;
import iron.object.Object;
import iron.math.Vec4;
import armory.trait.physics.RigidBody;
2020-11-02 15:51:34 +01:00
using armory.object.TransformExtension;
2018-11-12 21:06:12 +01:00
class ApplyTorqueImpulseNode extends LogicNode {
2019-12-19 23:54:08 +01:00
public function new(tree: LogicTree) {
2018-11-12 21:06:12 +01:00
super(tree);
}
2019-12-19 23:54:08 +01:00
override function run(from: Int) {
var object: Object = inputs[1].get();
var torque: Vec4 = inputs[2].get();
2020-11-02 16:55:11 +01:00
var local: Bool = inputs.length > 3 ? inputs[3].get() : false;
2019-12-19 23:54:08 +01:00
2018-11-12 21:06:12 +01:00
if (object == null || torque == null) return;
#if arm_physics
2019-12-19 23:54:08 +01:00
var rb: RigidBody = object.getTrait(RigidBody);
2020-11-02 15:51:34 +01:00
!local ? rb.applyTorqueImpulse(torque) : rb.applyTorqueImpulse(object.transform.worldVecToOrientation(torque));
2018-11-12 21:06:12 +01:00
#end
runOutput(0);
}
2020-11-02 15:51:34 +01:00
2018-11-12 21:06:12 +01:00
}