# Haxe node output help

#1

I want to make a “get velocity” node and actually have everything working, put the output only seems to work with the “Print” node. Plugging it into any other node returns the same result as if the vector were 0,0,0. Can anyone please point me to the right direction?
Here the python code:

class GetVelocityNode(Node, ArmLogicTreeNode):
'''Get velocity node'''
bl_idname = 'LNGetVelocityNode'
bl_label = 'Get Velocity'
bl_icon = 'GAME'
def init(self, context):
self.inputs.new('ArmNodeSocketObject', 'Object')
self.outputs.new('NodeSocketVector', 'Vector')

and the haxe:

package armory.logicnode;
import iron.math.Vec4;
import iron.object.Object;
class GetVelocityNode extends LogicNode {
public var locbef = new Vec4();
public var final = new Vec4();

public function new(tree:LogicTree) {
super(tree);
}

override function get(from:Int):Dynamic {
var object:Object = inputs[0].get();
if (object == null) return null;
final = locbef.sub(object.transform.world.getLoc());
locbef = object.transform.world.getLoc();
return final;
}}

#2

At first sight, you are dealing with Set Velocity and want to add Get Velocity that match with it… so does not it miss already a test to know if the object is of type arm_physics ? Then if you want to send a speed like a distance that separate 2 points (locbef, final) … isn’t to set your output like = Vec4.distance(final,locbef) ?

But globally if it you are not dealing with Set Velocity, it’s you that defines the speed at init or during the play, using a vector as a variable … so if you read this variable, you have your speed. So maybe this node is not necessary/ useful.

Exemple:
1= at start I create the variable Vitesse

2=during play I get Vitesse and can use it like that to translate my object

#3

@Didier I want to be able to use it on any object, without having do deal with if it is currently being moved with what method and also having to consider physics.
The Haxe script just outputs the subtraction (final) of the objects current position from the one on its last frame(locbef) (at least thats what it is supposed to do).
Here is a node setup that does the same.

My goal is simply to shrink it down to one node.

#4

@Simonrazer if you set the “vitesse” as in the precedent nodes I proposed to you, seems then you only then need to shrink 3 simples nodes into that into the frame Get Velocity in this thereafter picture ?

#5

But your setup doesn’t take into account physics if the object is an rigidbody. When it falls down a cliff, it will still say 0.

#6

Sure , it 's the reason why I asked you if arm_physics was tested in your script at first comment … will test too

#7

Ohhhhh sorry, I didn’t quite understand that part of your comment. I tried to find something already build-in, but failed. And I believe that the object would need to have Rigidbody enabled then, which is also not cool.