Files
pogo-stick-game/Assets/VisualiseCenterOfMass.cs
ondroftw cac112a79c Add center of mass visualization and update mesh references
- 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.
2025-10-07 21:07:27 +02:00

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);
}
}
}