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?
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)
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?
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.