Equal distance between two objects

I have two meshes here, and I need a function to calculate the mid location between these two meshes, sort of like this idea in the pseudo code below.

Does anyone have a handy function already made?

(w1.getAbsolutePosition() + w2.getAbsolutePosition() ) / 2

:slight_smile: Hi FBa.

var betweenThem = BABYLON.Vector3.Center(mesh1.position, mesh2.position);

https://playground.babylonjs.com/#4F33I3#13
(betweenThem == calc2 … in that playground)

Should work for ya. Be well.

4 Likes

Thanks so much for the prompt reply!!! I knew there was a way. Overlooked the Center function…

Work in progress!!

1 Like

heh. Me, too… for my entire life + over an hour. First, I went looking-at ways to “sum” the boundingBoxes of both mesh… to make a single new one, and then use ITS center. That appeared to be a 12-step process (but thx for the sweet doc about it, @PirateJC).

So then I did that calc1 version you see in the playground… and then I decided I was going to stare at all the methods on Vector3 class… until I found something easier and wiser… because I KNEW it HAD TO be there, somewhere. It’s just too handy to have not yet been coded.

Then it jumped off the screen and kissed me on the end of my nose… and I said to myself… “ooh, this is going to make me look like a guru or super-pro”… even though I’m not so, and I just got lucky. :slight_smile:

Either way, YAY! I learned something new, and we both got to benefit from it. I’ve never used .Center() ever in my life, but I might, now. :slight_smile:

3 Likes