# Snap between objects

**URL:** <https://forum.babylonjs.com/t/snap-between-objects/44631>\
**Category:** Questions\
**Created:** [October 2, 2023, 11:59am UTC](https://forum.babylonjs.com/t/snap-between-objects/44631 "2023-10-02T11:59:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MarianG](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mariang/32/138_2.png) [@MarianG](https://forum.babylonjs.com/u/MarianG)\
**Post date:** [October 2, 2023, 11:59am UTC](https://forum.babylonjs.com/t/snap-between-objects/44631/1 "2023-10-02T11:59:05Z")

</div>

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](https://playground.babylonjs.com/#95GHCY#1)  
And visual example

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/b/9/b9f8f6c0d188f59796ea3acaae9bd2dfb8e3af53.png)  
Any idea is welcome? Thanks 🔥

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [October 2, 2023, 4:07pm UTC](https://forum.babylonjs.com/t/snap-between-objects/44631/2 "2023-10-02T16:07:05Z")

</div>

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](https://playground.babylonjs.com/#95GHCY#2)

The other dimension will highlight the offset issue.

---

<div class="post-metadata">

**Author:** ![MarianG](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mariang/32/138_2.png) [@MarianG](https://forum.babylonjs.com/u/MarianG)\
**Post date:** [October 2, 2023, 6:37pm UTC](https://forum.babylonjs.com/t/snap-between-objects/44631/3 "2023-10-02T18:37:47Z")

</div>

No waaaay 😲 It seems that I am like gpt, over time I become dumber 😅  
Thank you! 🍻
