Files
pogo-stick-game/Assets/VisualiseCenterOfMass.cs
ondroftw 021d01fbb1 Integrate Cinemachine and enhance debug capabilities
- Add Cinemachine package (v3.1.4) and configure related components (e.g., CinemachineBrain, CinemachineCamera, CinemachineFollow).
- Update scene with new Cinemachine virtual camera for improved camera behaviors and tracking.
- Extend `DebugUi` to display grounded status and added supporting logic in `TestScript`.
- Refine physics logic in `TestScript` with grounded checks and updated jump action conditions.
- Minor adjustments to Rigidbody angular damping and ForceMode values.
2025-10-13 18:49:31 +02:00

38 lines
903 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);
}
}
}