armory/Sources/armory/logicnode/ApplyImpulseAtLocationNode.hx

38 lines
938 B
Haxe
Raw Normal View History

2018-04-13 05:29:05 +02: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;
class ApplyImpulseAtLocationNode extends LogicNode {
2018-04-13 05:29:05 +02:00
2019-12-19 23:54:08 +01:00
public function new(tree: LogicTree) {
2018-04-13 05:29:05 +02:00
super(tree);
}
2019-12-19 23:54:08 +01:00
override function run(from: Int) {
var object: Object = inputs[1].get();
var impulse: Vec4 = inputs[2].get();
2020-11-02 16:55:11 +01:00
var localImpulse: Bool = inputs.length > 3 ? inputs[3].get() : false;
2020-11-02 15:51:34 +01:00
var location: Vec4 = inputs[4].get();
2020-11-02 16:55:11 +01:00
var localLoc: Bool = inputs.length > 5 ? inputs[5].get() : false;
2019-12-19 23:54:08 +01:00
2018-06-14 14:52:05 +02:00
if (object == null || impulse == null || location == null) return;
2018-04-13 05:29:05 +02:00
#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
if (localLoc) {
location.applyQuat(object.transform.rot);
}
2020-11-02 15:51:34 +01:00
!localImpulse ? rb.applyImpulse(impulse, location) : rb.applyImpulse(object.transform.worldVecToOrientation(impulse), location);
2018-04-13 05:29:05 +02:00
#end
2018-10-22 10:10:33 +02:00
runOutput(0);
2018-04-13 05:29:05 +02:00
}
2020-11-02 15:51:34 +01:00
2018-04-13 05:29:05 +02:00
}