Interactive Furniture & Physics

Hello forum people,

I am looking to include physics based elements to a project I am working on, and I am looking for advice and direction from those with more experience than me. Basically I have coded player controlled physics interaction with objects similar to what you see in games like Amnesia, or before that with Half Life 2. I am tracing a line from the camera and having it place a Physics handle on physics enabled objects to they can be influenced by the player.

My goal is to have functioning dressers, cabinets, and the like for players to open and retrieve objects from inside.

I have not made any assets yet, as I am currently just trying to wrap my head around the best possible solution. So far the only ways I can think of are three;

1.) Simply put the drawers in the dressers, and players might easily yank them clear out of the furniture

2.) Model them with back stops to keep them from sliding out

3.) Rig the furniture with skeletons to ‘lock’ the drawers to the main piece

Each method comes with issues that I am not sure of. Number one is just sloppy, and I am not entirely sure I was objects strewn all over the place. It is intended to by multiplayer so this is not ideal. Number two seems like a good idea, but I am not sure how well the physics and collision meshes will work here. It might be fine, or I might get radically exploding assets as the physics all battles itself. Last, skeletons are used in animated furniture, and it seems like a good idea, but I have no idea what sort of skeletal structure to use for furniture. For organic thinks like people I fully understand how it works… but drawers in a dresser?

Anyways, thanks for the help in advance, you all are life savers,
~vgnevar

Have look at PhysicsConstraints and PhysicsConstraintComponent in particular.

Take the drawer for example.

You could model the dresser and the drawer separately. Then create a Blueprint and add the dresser and the drawer als StaticMeshComponents. After that just add a PhysicsConstraintComponent for each drawer and connect the drawer to the dresser base (by choosing ComponentName1 and ComponentName2).
In the PhysicsConstraint just set the Linear Limits (either X or Y depending on the local object orientation) and set it to Limited and define how far the drawer is supposed to move inside the dresser.

Done.

If you want a door instead of a dresser, change the constraint from linear to angular so the door can swing open.

Constraints seem like they could solve it, however there is another variable at work.

I used constraints to keep a door in place at the hinges so I could open and close it with physics. The issue is, the door is locked in place where ever it is placed, and I am using some code to randomly place assets. Would the constraints function off their own location or would this method require pre-placed assets to function? Likewise, if there needs to be a possibility of the dresser plus all it’s drawers being thrown across a room, will the constraints tie to the parent dresser or do they tie to their location in the world grid?

You used ConstraintActors for that, didn’t you? They use world location to constrain the connected objects.

PhysicsConstraintComponents work in the Actors/Blueprints local space instead of world space and therefore follow the root of the actor.

Here is a simple door setup:

So for precedural content, I would advice encapsulating your doors/dressers and other stuff in blueprits with their own local constraints.

Alright, so the different constraints operate at different levels.

If I use the Components instead of the Actors the objects will be constrained to themselves within their ‘local’ asset space, therefore locking drawers in a dresser, or pinning cabinet doors to the armoire.

Another issue I had, which might be related to my choice of constraints, is that when I opened my door using the ‘gravity gun’ that I coded it would lose it’s collision detection on the player actor. Before I hit it with my Physics Handle, I could push it around with my character’s collisions. As soon as I used my physics interaction with the door, it would start ignoring the player’s collision, but not other objects collision. Is this due to my choice in constraints by chance?

I doubt that the collision problem has anything to do with the constraints. My bet is on the PhysicsHandle. I found that the PhysicsHandle had some strange behaviour like disabling gravity for the handled object and a few other things.

For randomly placed content you can spawn the constraints and the actors to be constraint at runtime.
That works well. We spawned entire powered ragdolls as robots that way, which were made off nothing but constraints and actors.

Other than that I would also go with 2.
Constraints and physics can be made very robusr in our experience so far.

I appreciate all the free help folks. Everything seems to be working well now.

I am still having issues with my “gravity gun” cancelling out the collision meshes of the objects I use it on. Any insight into that DennyR? You grav gun seems to work flawlessly.