Merge pull request #2318 from QuantumCoderQC/navMeshImprove
Small improvement to Navigation nodes
This commit is contained in:
commit
a4ab1dcc98
25
Sources/armory/logicnode/GetAgentDataNode.hx
Normal file
25
Sources/armory/logicnode/GetAgentDataNode.hx
Normal file
|
@ -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
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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<Vec4> = null;
|
||||
var index = 0;
|
||||
|
|
13
blender/arm/logicnode/navmesh/LN_get_agent_data.py
Normal file
13
blender/arm/logicnode/navmesh/LN_get_agent_data.py
Normal file
|
@ -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')
|
|
@ -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')
|
||||
|
||||
|
|
Loading…
Reference in a new issue