Moving a box out from the corner of a room

I’m having trouble automatically moving a box away from the corner of a room (so it is no longer colliding with any walls). I have a box in the corner, which is initially not actually colliding with any walls but practically touching them. However, if I rotate the box, it’s bounding box increases in size, and so it intersects with both walls. I want to move it away enough so it is no longer colliding. However, I only have the co-ords of the centre of the walls (since I’m using bounding boxes), and if I move the box away from the wall using this co-ord, it actually moves it further into the other wall (and vice versa). Eventually it gets pushed out the other side through both walls!

Unfortunately, collisions between bounding boxes don’t return the actual collision point or normal so I can’t use that. Is there any way to solve this?

Thanks in advance

The easiest way would be to use bullet and let it do this for you.

Thanks for the suggestion. It’s for a networked FPS though, so I need to be in full control of the spatials, including rewinding time.

The physics would be done on the server, though… so I don’t see why that’s an issue.

Else, I guess you will have to implement your own physics engine that supports rewinding time.

50% of a physics engine is collision detection and the other 50% is collision resolution. You need both of those things to move a box out from the corner.

Edit: and why do you have spatials on your server? Gets kind of crazy at some point.

I’ve got my own simple physics engine; nothing special, but it handles collisions and gravity and bouncing. I’m just having trouble moving spatials back when they overlap. I think my solution will be to use non-rotating boundingboxes.

I run a headless server, mainly so I can run the same code on the client and the server. Seems to work well enough, though is there a better way?

Usually treating Spatials as game objects will end up collapsing under its own weight at some point. You pull in a lot of baggage with a Spatial that is unneeded in a game object and its too tempting to modify things directly, etc.

…especially in a networked game, it usually ends up being 1000x better to have real game objects and let the Spatials just be the view-side expression of those.

FWIW, I have just come up with a solution to this: taking each axis in turn, if the box’s bounding box is within the boundingbox of the wall, then don’t move the box on that axis. Otherwise, move the box away from the wall along that axis.

Regarding your suggestion to only use JME on the client, I’ll make a note, but it will mean a lot of refactoring, so maybe I’ll do it in version 2 of my engine :slight_smile:

Note that this method will not result in physically correct motion - just thought I’d mention it since you referred to writing your own physics engine.

How do you mean?

Suggestion was to only use Spatials on the client. You can’t get away from using some JME on the server… after all JME’s math package is pretty convenient, a lot of folks use SpiderMonkey, etc…

For a full client server app example, you can look here:
Non ES version:

ES version:

1 Like

Just re-read your original post - you’re probably ok, actually. I thought you were referring to doing this as part of dynamic movement, not static position. If you were doing something like this as the box is dynamically colliding with the wall, you’d have to be careful regarding the point and angle of contact with the wall to correctly calculate the direction that the box will rebound towards. Just moving it out of the wall would lose that information and you wouldn’t get a correct rebound - hence my earlier post about physically incorrect motion.