Modify Navigation Go To Location Node

This commit is contained in:
QuantumCoderQC 2021-09-03 21:00:33 +02:00
parent 8caf859db9
commit 32b745f829
2 changed files with 15 additions and 2 deletions

View file

@ -13,15 +13,26 @@ class GoToLocationNode extends LogicNode {
override function run(from: Int) {
var object: Object = inputs[1].get();
var location: Vec4 = inputs[2].get();
var speed: Float = inputs[3].get();
var turnDuration: Float = inputs[4].get();
if (object == null || location == null) return;
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");
#if arm_navigation
// Assume navmesh exists..
var from = object.transform.world.getLoc();
var to = location;
assert(Error, Navigation.active.navMeshes.length > 0, "No Navigation Mesh Present");
Navigation.active.navMeshes[0].findPath(from, to, function(path: Array<iron.math.Vec4>) {
var agent: armory.trait.NavAgent = object.getTrait(armory.trait.NavAgent);
assert(Error, agent != null, "Object does not have a NavAgent trait");
agent.speed = speed;
agent.turnDuration = turnDuration;
agent.setPath(path);
});
#end

View file

@ -10,6 +10,8 @@ class GoToLocationNode(ArmLogicTreeNode):
self.add_input('ArmNodeSocketAction', 'In')
self.add_input('ArmNodeSocketObject', 'Object')
self.add_input('ArmVectorSocket', 'Location')
self.add_input('ArmFloatSocket', 'Speed', 5.0)
self.add_input('ArmFloatSocket', 'Turn Duration', 0.4)
self.add_output('ArmNodeSocketAction', 'Out')