Snap between objects

Hey!
I’ve got a new issue, and honestly, I’m almost embarrassed to admit that I just can’t figure out what’s happening here. I tried to simplify the situation as much as I could.
There’s a scene where I’m trying to snap two objects together: one that’s movable and another that’s positioned somewhere in the scene and attached to a different object. The weird thing is, this snapping works sometimes and other times… not so much. If it seems to work right off the bat, try panning the camera in different directions and… it’ll break
Here is the pg: https://playground.babylonjs.com/#95GHCY#1
And visual example


Any idea is welcome? Thanks :fire:

Your algorythm does not account for the shape of the mesh you drag so depending where you click on it, you will create an offset.

You would need to check for each side if it should snap or not.

A quick example of how you could force the correct x here: https://playground.babylonjs.com/#95GHCY#2

The other dimension will highlight the offset issue.

2 Likes

No waaaay :astonished: It seems that I am like gpt, over time I become dumber :sweat_smile:
Thank you! :beers: