Find distance between vectors on single relative axis? InverseTransformPoint?

Hi all,

I’m very new to BabylonJS (coming from a Unity background). Appologies if this has ever been answered. I’m trying to find a distance on a single relative axis (similar to this question Find Distance on Single, Relative Axis? - Unity Answers).

My issue is that I don’t know how to do a InverseTransformPoint in BabylonJS.

So can anybody either:

A: Help me with the maths behind InverseTransformPoint or
B: Give me an alternate solution to my actual problem.

Any help would be really appreciated. Thanks :slight_smile:

Hello and welcome!
So you want to get the distance between two meshes on a specific world axis? Or local axis?(but then which object local space?)

So I need it on a local axis. Let me explain it better:

Vector A (car)
Vector B (road centre)

if the car is on the far left edge of the road, I need to know the distance on the x axis between them - taking the cars rotation into account.

Ok so you can compute invMatrix

var invMatrix = BABYLON.Matrix.Invert(road.getWorldMatrix())

Then you can transform car.position with:

var invertedPosition = BABYLON.Vector3.TransformCoordinates(car.position, invMatrix)

Wow, thanks for the quick reply. I’ve not tried it yet, but this is what I’m trying to achieve (the blue line):

Yep that should be close:)

Thanks again! :slight_smile: