Skip to main content

CenterOfMassSetter

A class in Root.Township, the global namespace.

Sets a rigidbody's centre of mass and keeps its inertia tensor sane. Hand adds a temporary one to held pickups and removes it once they're let go.

Constructors​

MemberWhat it is
CenterOfMassSetter()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

4 private and internal fields
MemberWhat it is
private Rigidbody cachedRigidbodyCached rigidbody behind Rigidbody.
private Vector3 centerOfMassSerialized local centre of mass.
private bool isFixingTensorWhether setting the centre of mass also repairs the inertia tensor.
private static Logger loggerNLog logger for inertia tensor errors.

Properties​

MemberWhat it is
Vector3 CenterOfMass { get; set; }The rigidbody's centre of mass. Setting it also fixes NaN or infinite inertia tensors and raises the Y tensor if isFixingTensor is on.
bool IsTemporary { get; set; }Marks a setter that Hand added at runtime, so it is removed when the pickup is released.
Rigidbody Rigidbody { get; }The rigidbody on this object. If there is none, the component destroys itself.
1 private and internal property
MemberWhat it is
private bool IsDestroying { get; set; }True after SetDestroy until the component goes or CenterOfMass is set again.

Methods​

MemberWhat it is
void SetDestroy()Schedules this component for removal at end of frame, or removes it at once if inactive.
5 private and internal methods
MemberWhat it is
private void Awake()Applies the serialized centre of mass, then resets the rigidbody's centre of mass and inertia tensor.
private IEnumerator DelayDestroy() (iterator)Destroys this component at end of frame unless it was given a new centre of mass meanwhile.
private void OnDestroy()Resets the rigidbody's centre of mass and inertia tensor to Unity's defaults.
private void OnDrawGizmosSelected()Draws a sphere at the centre of mass.
private void OnValidate()Applies the serialized centre of mass in the editor.

Used in​

Members of other types that take, return or hold a CenterOfMassSetter: