- Home /
Picking up an object by it's center
Hi All,
I have a character who has the ability to pick up and throw other characters / objects. The way I have done this so far is to use transform.find to get the handbone location for the character then parent this to the object. I then use translate to follow the movement of the hand.
This all works great when testing on cubes, BUT on the enemy Character mesh the pivot point is at the feet, not in the middle of the mesh. The effect is that my grab animation appears to pick the character up by his feet (which is kind of cool, but not what I was aiming for!).
I have tried adding an empty game object as a child of the character I am picking up, but the character does not follow the object. I guess I can try adding an empty game object as the parent of the character, but to do that I would need to re-write a bunch of other people's code that relies on the mesh being at the top level (although I feel like this might be the way to go!).
Does anyone have a simple way of picking up an object at a location other than the center of it's transform?
Answer by NickWu · Jul 15, 2016 at 05:41 PM
You can get the local position of the empty gameobject you created.
use that as a reference offset, when you pick up the character, offset the local position with that reference.
Let's say you have a character, with an empty object as a child, where the local position is (0.0f, 1.0f, 0.0f), which is 1 unit above the feet.
When you pick up the character, set that character as a child of your hand, instead of setting the local position to Vector3.zero, set it to (0.0f, -1.0f, 0.0f)
Answer by JoshDangIt · Jul 15, 2016 at 06:02 PM
In addition to Nick's answer, You can try to use the enemy's Renderer.bounts.center to find that offset.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Push character away 0 Answers
How can I set a default pose for my character? 7 Answers
Vertex coloring isn't working 2 Answers