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.
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.