diff --git a/Sources/armory/logicnode/GetAgentDataNode.hx b/Sources/armory/logicnode/GetAgentDataNode.hx new file mode 100644 index 00000000..163b1388 --- /dev/null +++ b/Sources/armory/logicnode/GetAgentDataNode.hx @@ -0,0 +1,25 @@ +package armory.logicnode; + +import iron.object.Object; + +class GetAgentDataNode extends LogicNode { + + public function new(tree: LogicTree) { + super(tree); + } + + override function get(from: Int): Float { + var object: Object = inputs[0].get(); + + assert(Error, object != null, "The object to naviagte should not be null"); + +#if arm_navigation + var agent: armory.trait.NavAgent = object.getTrait(armory.trait.NavAgent); + assert(Error, agent != null, "The object does not have NavAgent Trait"); + if(from == 0) return agent.speed; + else return agent.turnDuration; +#else + return null; +#end + } +} \ No newline at end of file diff --git a/Sources/armory/logicnode/GoToLocationNode.hx b/Sources/armory/logicnode/GoToLocationNode.hx index 31fb6cd5..048c0343 100644 --- a/Sources/armory/logicnode/GoToLocationNode.hx +++ b/Sources/armory/logicnode/GoToLocationNode.hx @@ -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) { 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 diff --git a/Sources/armory/trait/NavAgent.hx b/Sources/armory/trait/NavAgent.hx index 1ba4c7da..ef6dba04 100644 --- a/Sources/armory/trait/NavAgent.hx +++ b/Sources/armory/trait/NavAgent.hx @@ -8,9 +8,9 @@ import iron.system.Tween; class NavAgent extends Trait { @prop - var speed: Float = 5; + public var speed: Float = 5; @prop - var turnDuration: Float = 0.4; + public var turnDuration: Float = 0.4; var path: Array = null; var index = 0; diff --git a/blender/arm/logicnode/navmesh/LN_get_agent_data.py b/blender/arm/logicnode/navmesh/LN_get_agent_data.py new file mode 100644 index 00000000..b26d4f8c --- /dev/null +++ b/blender/arm/logicnode/navmesh/LN_get_agent_data.py @@ -0,0 +1,13 @@ +from arm.logicnode.arm_nodes import * + +class GetAgentDataNode(ArmLogicTreeNode): + """Gets the speed and turn duration of the agent""" + bl_idname = 'LNGetAgentDataNode' + bl_label = 'Get Agent Data' + arm_version = 1 + + def arm_init(self, context): + self.add_input('ArmNodeSocketObject', 'Object') + + self.add_output('ArmFloatSocket', 'Speed') + self.add_output('ArmFloatSocket', 'Turn Duration') \ No newline at end of file diff --git a/blender/arm/logicnode/navmesh/LN_go_to_location.py b/blender/arm/logicnode/navmesh/LN_go_to_location.py index e60e743f..11a1b4b4 100644 --- a/blender/arm/logicnode/navmesh/LN_go_to_location.py +++ b/blender/arm/logicnode/navmesh/LN_go_to_location.py @@ -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')