- Implement `VisualiseCenterOfMass` script to draw gizmos for Rigidbody center of mass. - Replace mesh references with updated versions in the scene. - Adjust physics settings including center of mass and implicit settings.
38 lines
902 B
C#
38 lines
902 B
C#
// 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<Rigidbody>();
|
|
}
|
|
|
|
private void OnDrawGizmos()
|
|
{
|
|
if (_rb == null)
|
|
_rb = GetComponent<Rigidbody>();
|
|
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);
|
|
}
|
|
}
|
|
} |