Files
LNXSDK/leenkx/Sources/leenkx/logicnode/ApplyImpulseAtLocationNode.hx
2025-01-22 16:18:30 +01:00

38 lines
957 B
Haxe

package leenkx.logicnode;
import iron.object.Object;
import iron.math.Vec4;
import leenkx.trait.physics.RigidBody;
using leenkx.object.TransformExtension;
class ApplyImpulseAtLocationNode extends LogicNode {
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
var object: Object = inputs[1].get();
var impulse: Vec4 = inputs[2].get();
var localImpulse: Bool = inputs.length > 3 ? inputs[3].get() : false;
var location: Vec4 = new Vec4().setFrom(inputs[4].get());
var localLoc: Bool = inputs.length > 5 ? inputs[5].get() : false;
if (object == null || impulse == null || location == null) return;
#if lnx_physics
var rb: RigidBody = object.getTrait(RigidBody);
if (!localLoc) {
location.sub(object.transform.world.getLoc());
}
!localImpulse ? rb.applyImpulse(impulse, location) : rb.applyImpulse(object.transform.worldVecToOrientation(impulse), location);
#end
runOutput(0);
}
}