When I move the object next to another object with the mouse, I want them to come side by side without any space between them, like a magnet?

When I move the object next to another object with the mouse, I want them to come together like a magnet, without any space between them? How can I do it ?

want to show us all what you have done so far? This question can be answered in many different ways, based on the use case.

Hello

When two cubes approach each other, I want them to stick to each other without overlapping.How can I do it ?

You can use collision detection for that:

Camera Collisions | Babylon.js Documentation (babylonjs.com)

Collusion does not work for me. I want the objects to stick to each other according to their boundaries when held with the mouse cursor and brought closer to the other object.

And this is why we ask for a reproduction of something that doesn’t work. Providing a scene with two boxes (at the same position) and no real explanation as to what isn’t working will not help us help you. How do you pick, where are they positioned. are they always boxes? spheres? How does 2D mouse movement translates to 3D space (again - in your case)? Collisions does solve your initial question, but doesn’t solve the problem in your use-case.

Instead of us doing your homework, show us everything you have done, until it doesn’t do what you want it to do. We will always be happy to help in those scenarios!

I have two objects in the repo and as these two objects approach each other, I want them to stick to each other from the edges and not overlap.

Take a look at this demo :slight_smile: Collision and "attachment points" - #4 by carolhmj

1 Like

Also:

1 Like

Two objects stick together when they approach each other, but I want the side faces of the two objects to stick to each other when they approach each other. They should not be intertwined. How can I do this?

hello again everyone

I have two boxes and they can move in all directions. I want them to attract each other like magnets. I want the attraction to stop as soon as the two boxes come into contact. How can I do it?

Babylon.js Playground (babylonjs.com)

You can validate the drag and say if it should drag or not.

1 Like

My goal is that it will be draggable. When two objects approach each other, it does not matter from which side they approach, I want it to stick from where it approaches, but they will not intertwine, it will stop as soon as it touches.

have you checked the playground?

yes ı checked my playground I don’t have a problem.Can you help me with the problem I described?

Do you want to explain what you tried? what is working and what not?
I hope someone else from the community can help, because I have no idea what you are trying to achieve.

RaananW’s PG does exactly what you want here.

It doesn’t do exactly what I want, but I also want it to stick to each other at its borders, just like a magnet.

it is a starting point. Now it is up to you to take it, and make it your own.
We don’t provide you with a final project for you to use. We provide you with solutions, in case they might not be fully documented or clear.

It is your task to take it, understand it, and fix it to your needs

1 Like

Do you want it to stay attached afterwards? you can use parent.

Box2.parent = box1