Placing an object

Let’s say I have a game, where you build structures. Each gameobject can be in one of three positions:

In your hand (being carried)
Lying on the ground
Being set upright

For example: A log. When you carry it, its side rests in your palm. When lying on the ground, its side rests against the ground. When set in the ground (planted, like a pole), its pivot needs to be in the center of the log, a little ways from the bottom.

A sword. In your hand, it is vertically flat, and points forward. On the ground, it is lying on its side (90 degrees rotation from when it is in your hand), and if (for whatever reason) you wanted to stick it in the ground, its pivot would be in inside the sword, near the blade tip.

So, each object needs three different pivots and rotations that it needs to be set at, depending on whether or not it is being carried, on the ground, or planted.

Any ideas on how to approach this? My current approach is to have this:

Post
    Hand
    Ground
    Planted

Each child would have its position and rotations set to position the object correctly. The gameobject would be attached to the appropriate child. The Post parent would just be placed on the ground or attached to your hand. The child objects would automatically handle rotation and adjustment.

Any thoughts on this?

Not sure whether you solved this problem already but just to add my thoughts:

Granted there’s probably a better approach out there, my suggestion to you would be to have a separate ‘parent’ mount point for each of the three states; namely, in-hand, on-ground, planted.

Start by creating an empty GameObject (let me call it the ‘MountPoint’) and giving it an meaningful name for the given state. For the ‘in-hand’ state, I’d say you need to make the Mount Point a child of the left/right hand that will hold the sword. Then you would make the sword object to be the child of the in-hand MountPoint.

What I’d do to ensure the accurate positioning of the sword in character’s hand is to drag both the character object and sword object into the Scene and move the sword in the palm of your character before applying the changes to the prefab.

A similar method can be used for the other two states. Again, I am only assuming here that you’d want your sword to be located at a specific spot on your map and that’s where you would need to place your MountPoint. Once the sword is assigned to the MountPoint as a child, you would only need to modify the location and/or rotation of the MountPoint to give the sword a visibly different orientation (e.g., lying flat on the ground vs. “planted” on the ground).

Again, probably not the smartest way to do this but it worked for me. I hope it helps. :slight_smile: