x


centerOfMass and local coordinate origin

Is there a way to set the origin of the local coordinate system of a rigidbody equal to the centerOfMass automatically calculated by the Unity engine for a MeshCollider or complex of primitives?

I don't want to arbitrarily set the centerOfMass, since I want to use the auto-calculated one, but I want to apply rotational forces relative to the centerOfMass.

I'm using addRelativeTorque to apply rotational forces.

Thank you for your time, please ask me to clarify if necessary.

more ▼

asked Oct 14 '10 at 09:34 PM

fzzr gravatar image

fzzr
50 2 2 11

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

You could add an intermediate transform to act as an offsetter. E.g.

var offsetter = GameObject(transform.name + "Offsetter");
offsetter.transform.position = transform.TransformPoint(rigidbody.centerOfMass);
offsetter.transform.rotation = transform.rotation;
offsetter.transform.parent = transform.parent;
transform.parent = offsetter.transform;
more ▼

answered Oct 28 '10 at 05:25 AM

Max Kaufmann gravatar image

Max Kaufmann
573 10 12 21

Thanks! That looks like just what the coder ordered.

Oct 28 '10 at 01:32 PM fzzr
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2158
x1784
x116
x13
x8

asked: Oct 14 '10 at 09:34 PM

Seen: 1021 times

Last Updated: Oct 14 '10 at 09:34 PM