Find the distance between two meshes

Hi!

I have two objects, and I’m trying to find the distance between them. I hope this is possible, and if at all possible I would like a single digit number. Kinda like the getlinearvelocity for physics objects.

Thanks for any help, sorry if it is hard to understand.

Givo

(For the distance between the meshes centers…) take world (absolute) position vector of mesh 1 and subtract world (absolute) position vector of mesh, then take the length() function.

https://doc.babylonjs.com/api/classes/babylon.vector3

I’d recommend the book Mathematics for 3D Game Programming and Computer Graphics if you’d like to learn some essential/handy math for 3D projects:

3 Likes

Oh, yoink.

I was using BABYLON.Vector3.Distance(p1,p2) btw.

3 Likes

I give you an answer, and you do the same to me! :upside_down_face:
Thanks for the help.

Cool @withADoveInOneHand ! That function Distance on Vector3 will save me some code lines on making the Math myself. From time to time, new functions appear in the API (at least to me) that make my code easier and smaller. Whoohoo :slight_smile:

Thanks for the online PDF copy of the book @Givo I had bought the book already earlier with my business budget to show support to the author. And as a expert on several business and IT topics I get send most books for free anyways to review…

1 Like

Hi @Givo
Please avoid posting anything illegal :slight_smile:
https://forum.babylonjs.com/faq#stealing

Fixed!

1 Like

Sorry.

I did a google search. @Deltakosh is it stealing if I post my google search query?

Sorry. :no_mouth: I just thought I would put it out there.

You should just communicate using PM in that case

ok.

Is there a code or playground i can see, how to measure distance using pickedMesh between two opoints ?

https://playground.babylonjs.com/#JIHTLS#1