armory/Sources/armory/logicnode/CastPhysicsRayNode.hx
rbx775 fab8795e8e
fix an exception where hitPointWorld gets null.
...due to too short Rays set by the user.
Suggestion for the fix by zicklag, see here: http://forums.armory3d.org/t/bullet-physics-keeps-freezing-the-games/2925/2
Can confirm its working now.
2019-04-01 11:42:48 +02:00

43 lines
987 B
Haxe

package armory.logicnode;
import iron.math.Vec4;
class CastPhysicsRayNode extends LogicNode {
var v = new Vec4();
public function new(tree:LogicTree) {
super(tree);
}
override function get(from:Int):Dynamic {
var vfrom:Vec4 = inputs[0].get();
var vto:Vec4 = inputs[1].get();
if (vfrom == null || vto == null) return null;
#if arm_physics
var physics = armory.trait.physics.PhysicsWorld.active;
var rb = physics.rayCast(vfrom, vto);
if (from == 0) { // Object
if (rb != null) return rb.object;
}
else if (from == 1) { // Hit
var hitPointWorld:Vec4 = rb != null ? physics.hitPointWorld : null;
if (hitPointWorld != null) {
v.set(hitPointWorld.x, hitPointWorld.y, hitPointWorld.z, 1);
return v;
}
} else { // Normal
var hitNormalWorld:Vec4 = rb != null ? physics.hitNormalWorld : null;
if (hitNormalWorld != null) {
v.set(hitNormalWorld.x, hitNormalWorld.y, hitNormalWorld.z, 0);
return v;
}
}
#end
return null;
}
}