How to get distance between 2 objects...as a simple number?


#1

How can you find out how many blender units / meters / whatever units apart two points are?

For example, I’d like to plug in two objects locations and to get back a float saying how far apart they are (eg 3.816 units).

The obvious choice would seem to be the distance node. For some reason that I have trouble fathoming though, rather than return a simple number, this node returns… a four dimensional vector (!!!)

Alternately, is there a way to use nodes to convert this vector into a simple number representing the distance?


#2

If it can help you, thereafter some code extract of what I use to measure the distance between the end effector of a robot arm and a goal (see here IA, Python and Armory 3d/Blender) and maybe you could reuse :

// Fetch goal
var tr = iron.Scene.active.getChild(goalname).transform;
var goal = new iron.math.Vec4();
goal.set(tr.worldx(), tr.worldy(), tr.worldz()); 


var dist:Float = Vec4.distance(goal, effLoc);


#3

Thanks! I was hoping for a way with logic nodes, but I’ll try this and see how it works…


#4

Just made a PR for a way to do that in nodes :slight_smile: :

Edit: It just got merged so you can get it with the Armory updater.

image


#5

@zicklag - You are awesome. Thank you! This is exactly what I needed.

I don’t want to seem ungrateful, but wouldn’t this make more sense to add this into the Get Distance node, rather than the Vector Math node though?

I imagine that anyone looking to get the distance between two points as a float would automatically look at the Get Distance node, rather than a node called “Vector Math”.

If you don’t want to add it to the current Get Distance node, then how about putting it in a new node called “Get Distance (Value)”. The current Get Distance node could be renamed to “Get Distance (Vector)”.


#6

Glory to God. :slight_smile:

When I get time, I’ll check that out. :+1: I didn’t know there was a get distance node already. Ping me if I don’t get to this within a couple of weeks or something like that.