Hi there,

I once upon a time tried to get the Babylon repo to build so I could contribute, but being completely new to typescript (JS and C# guy here) it kind of intimidated me and I gave up. I still plan to get it all working some day and figure out the ins and outs of TS but for now I have to ask you great devs to implement things for me (upon approval, of course).

So, I am thinking it would be cool to have a getDistanceToCamera() function that uses the camera’s global position, so it still works when I parent the camera to another thing. I am parenting the camera to allow it to rotate on all axis (so you don’t get the weird rotation around the poles but that breaks the getDistanceToCamera function. I had a similar issue here Gizmo size by TrevorDev · Pull Request #5398 · BabylonJS/Babylon.js · GitHub which TrevorDev fixed but oddly enough that code doesn’t seem to use that function so that function was never changed, unless I am mistaken.


I’m a C# guy too, but we all started somewhere!

To get that distance can you do (this may require computeWorldMatrix() on parent, if applicable)?
var distance = camera.getAbsolutePosition().subtract(otherMeshPosition).length();
otherwise if you make a PG maybe we can help. cheers.

edit: We don’t have extension methods like c# unfortunately, but we can monkey patch the prototype in a PG. that’s how I PG new methods usually.


Ping @trevordev

@Zephos in my PR I just needed to change position to globalPosition to get the correct distance when the camera is parented. Do you have a specific playground that you are trying to get to work? Brian’s answer seems like it should work.

Yeah I am just calculating distance from camera manually at this point. The new function would be a “nice to have” to avoid this kind of confusion but not a “must have” feature I think. I am not too worried about it. Now that I am aware I will hopefully not make the same mistake again.

1 Like