2017-04-03 22:29:46 +02:00
|
|
|
package armory.logicnode;
|
|
|
|
|
2017-09-30 00:32:06 +02:00
|
|
|
import armory.trait.navigation.Navigation;
|
2017-11-20 15:16:52 +01:00
|
|
|
import iron.object.Object;
|
|
|
|
import iron.math.Vec4;
|
2017-04-03 22:29:46 +02:00
|
|
|
|
2017-04-08 20:05:35 +02:00
|
|
|
class GoToLocationNode extends LogicNode {
|
2017-04-03 22:29:46 +02:00
|
|
|
|
2019-12-19 23:54:08 +01:00
|
|
|
public function new(tree: LogicTree) {
|
2017-04-04 23:11:31 +02:00
|
|
|
super(tree);
|
2017-04-03 22:29:46 +02:00
|
|
|
}
|
|
|
|
|
2019-12-19 23:54:08 +01:00
|
|
|
override function run(from: Int) {
|
|
|
|
var object: Object = inputs[1].get();
|
|
|
|
var location: Vec4 = inputs[2].get();
|
2021-09-03 21:00:33 +02:00
|
|
|
var speed: Float = inputs[3].get();
|
|
|
|
var turnDuration: Float = inputs[4].get();
|
2019-12-19 23:54:08 +01:00
|
|
|
|
2021-09-03 21:00:33 +02:00
|
|
|
assert(Error, object != null, "The object input not be null");
|
|
|
|
assert(Error, location != null, "The location to navigate to must not be null");
|
|
|
|
assert(Error, speed != null, "Speed of Nav Agent should not be null");
|
|
|
|
assert(Warning, speed >= 0, "Speed of Nav Agent should be positive");
|
|
|
|
assert(Error, turnDuration != null, "Turn Duration of Nav Agent should not be null");
|
|
|
|
assert(Warning, turnDuration >= 0, "Turn Duration of Nav Agent should be positive");
|
2017-04-03 22:29:46 +02:00
|
|
|
|
|
|
|
#if arm_navigation
|
2017-07-14 18:07:30 +02:00
|
|
|
var from = object.transform.world.getLoc();
|
2017-04-03 22:29:46 +02:00
|
|
|
var to = location;
|
2021-09-03 21:00:33 +02:00
|
|
|
|
|
|
|
assert(Error, Navigation.active.navMeshes.length > 0, "No Navigation Mesh Present");
|
2019-12-19 23:54:08 +01:00
|
|
|
Navigation.active.navMeshes[0].findPath(from, to, function(path: Array<iron.math.Vec4>) {
|
|
|
|
var agent: armory.trait.NavAgent = object.getTrait(armory.trait.NavAgent);
|
2021-09-03 21:00:33 +02:00
|
|
|
assert(Error, agent != null, "Object does not have a NavAgent trait");
|
|
|
|
agent.speed = speed;
|
|
|
|
agent.turnDuration = turnDuration;
|
2017-04-03 22:29:46 +02:00
|
|
|
agent.setPath(path);
|
|
|
|
});
|
|
|
|
#end
|
|
|
|
|
2018-10-22 10:10:33 +02:00
|
|
|
runOutput(0);
|
2017-04-03 22:29:46 +02:00
|
|
|
}
|
|
|
|
}
|