// CenterOfMassVisualizer.cs using UnityEngine; [ExecuteAlways] [RequireComponent(typeof(Rigidbody))] public class VisualiseCenterOfMass : MonoBehaviour { [Header("Gizmo Settings")] public Color gizmoColor = Color.cyan; public float gizmoSize = 0.05f; public bool drawLineToOrigin = true; private Rigidbody _rb; private void OnEnable() { _rb = GetComponent(); } private void OnDrawGizmos() { if (_rb == null) _rb = GetComponent(); if (_rb == null) return; // Rigidbody.centerOfMass is in local space var worldCom = _rb.transform.TransformPoint(_rb.centerOfMass); Gizmos.color = gizmoColor; Gizmos.DrawSphere(worldCom, gizmoSize); if (drawLineToOrigin) { Gizmos.DrawLine(_rb.transform.position, worldCom); } } }