- Home /
Move parent pivot point along with child Rigidbody?
I've constructed a shopping cart vehicle with a rigidbody attached. What I'd like to be able to do is, when stopped, pivot around the spot where the player wound stand were they pushing it. I can accomplish this by making the shopping cart a child of an empty gameobject (which serves as a pivot point), which I can then rotate to get the desired effect. The only problem with this is that this parent doesn't come along with the cart once it's moved from its starting point! This of course leads to some very strange rotation behaviour.
There's probably something simple I'm overlooking, but I would very much appreciate any insights into this issue.
You could try making the pivot point a child of the shopping cart and offset it's local position. That way, any time the shopping cart is moved, the pivot point will move with it.
Thank you for your response. The question that your solution leads me to is how I would go about achieving the pivot in that case. With the pivot as parent, I can just rotate its transform (or rotate simply through script), but with the pivot as child, I'm not sure how to approach that.
This is exactly what I needed, thank you! I wasn't aware of RotateAround, which I will certainly stow in my bag of tricks for the future.
Also, if you can convert your comment to an answer, I'll be able to check off "accept this answer as correct" for easier reading if anyone stumbles across this.
Answer by Key_Less · Nov 25, 2013 at 06:36 PM
Ah, I see now, sorry I read the original question incorrectly. You're using this pivot point to rotate the shopping cart object, not the camera.
Okay, so I would suggest still keeping the pivot point as a child object, so it will always translate with the shopping cart. Then you can use the pivot point for your rotation calculations;
Try something like this:
// Get the transform from the child object, pivot point.
var pivot = transform.FindChild("PivotPoint");
// Rotate the shopping cart around the pivot point's position.
transform.RotateAround(pivot.position, Vector3.up, 20 * Time.deltaTime);
I haven't been able to test this but I'm hoping it can lead you in the right direction.
Your answer
![](https://koobas.hobune.stream/wayback/20220613122731im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Instantiate an object as a child of the gameobject's parent 2 Answers
How to make an Instantiated prefab a Child of a gameobject that already exists in the hierarchy 3 Answers
Extreme slowdown during move request 1 Answer
VR Rigidbody not working with child colliders 0 Answers
Animated character with simple colliders on joints - rigidbody not finding child colliders. 0 Answers