Sliding boxes

Hello everyone.

I’m working on a small project. I want some boxes spawend in the world which I can click and move around with mouse and build simple structures. I got the movement using “SetWorldLocation” with “Sweep” set to true but the problem is when I “hit” an other box the one I’m moving just stops and the only way to move it is to pull it back from the hitted box. Is there a way to make the moved box “slide” along the other boxes so I can move it freely around them?

Not quite sure what you mean by ‘slide along’, but have you tried enabling physics? At least the other boxes would get out of the way.

Right now when I drag the small box into another box (the big one in this case) it stops. If I want to move it again I have to pull it back from the big box first. What I would like is when I move my mouse up or down or diagonal the box will move too (trying to get around it)

I think you have code that into the movement. Presumably these are blueprints?

When one hits another like that, it would know you mean, ‘on top’.

I found this:

It’s not quite the same thing, but maybe you get some ideas from there…

Thanks for the interest. I will take a closer look but in the meantime I did some testing with physics as you mentioned before.

It ALMOST works. Moving is perfectly smooth and just as I wanted but this time the moved box is slightly inside the obstacle when it touches it. I changed some physics/collision options but without any results. Any ideas about that?

Can you look at those cubes in the mesh editor? Is the collision good?

It looks like you made some of them with BSP, it might work better with just plain scaled cubes.

It is a regular cube from Basic Shapes and collisions looks ok.

Not sure basically. A tweak in the collisions settings might help, some experimentation is needed…

The rules applied to “slide” the box can vary too much for a general one-fits-all solution. If you manually use “SetWorldLocation”.

Maybe you can use overlap callbacks. As long it overlaps, try to find a better spot. As said, which spot is “better” depends on too many parameters, like how is your world build up, which control behaviour do you wish, has is to be very sticky to the cursor or is it able move freely?

I would try to think about what does define the “next best spot” in your world if it overlaps.

Otherwise you have to use pure physics. Which might be come the closest to find “next best spot” in case of collisions. That will not result in very smart solutions in mose cases but makes your world feel solid and works in easy situations like sliding at a wall.

Just use the vector between the center of your box and the destination and apply that as a force to your physical objects. If you pull the box against a wall, it will slide automatically at a spot where the force is minimal.