Good day, ladies and gentlemen, I’ve tried different ways to solve my task, but either they turn the code into spaghetti or they don’t work. I’m hoping for some advice and ideas.
The task is that the player should move furniture (an object) while holding down a button (e.g., R).
It looks like this:
The player approaches the object, holds down R, and while holding the button, the furniture moves in the same direction as the player. If the player releases the button, the object stops moving with them.
If you know or have played the system 1-to-1 like in the game Darkwood, it’s when you move furniture.
From the information I have:
I move my character using Rigidbody.
I’d prefer not to spam in the Update to avoid affecting performance, but if there’s no other way, so be it.
One of the unclear points for me is:
If the player is carrying furniture and bumps into an obstacle while still walking, the furniture continues to move, increasing the distance.
If you can recommend whether to handle this through collision or triggers, I’d appreciate it. Thanks in advance for any recommendations.
That’s just a bug… likely an architecture bug. When you grab a piece of furniture, wherever it is within your grabbing space should become the new “offset from me” position for that furniture to be at when you move.
Then the furniture just goes to that position. If you’re walking and bump into something and stop moving, your offset from me also stops moving.
This is all covered in gravity gun tutorials, of which there are many out on Youtube.
It may also need to be a two-step process that moves a “ghost” of the furniture first, to show the user where it will be, decides if it is valid (green) or invalid (red), colorizes the placeholder, then moves the furniture, but only if it is valid.
If the user drops the furniture when trying to put it in an invalid location, the furniture remains in its previous valid location. This is just basic UI/UX patterns that many gripper / mover / dragger games use.
The only thing different with a piece of furniture is if it has some requirements of being placed on a flat surface, or not fully penetrating other items. Physics can help you here but the more aggressively tight and constrained you are, you may need extremely high solver counts to get a satisfactory result, or you might need to do some of your own deconflicting and just inhibit moving the furniture into volumes that are not “adequately clear,” such as clear of colliders as tested by your code using an alternate method, such as a sphere or cylinder.
I don’t know what that even means, since that’s how things are done every frame.