File size: 906 Bytes
d883ffe | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | // Copyright (c) Meta Platforms, Inc. and affiliates.
using Meta.XR.Samples;
using UnityEngine;
namespace NorthStar
{
/// <summary>
/// Moves a colliders to the height and position of the tracked head
/// </summary>
[MetaCodeSample("NorthStar")]
[RequireComponent(typeof(CapsuleCollider))]
public class PlayerCollider : MonoBehaviour
{
private CapsuleCollider m_playerCollider;
[SerializeField] private Transform m_head;
private void Awake()
{
m_playerCollider = GetComponent<CapsuleCollider>();
}
// Update is called once per frame
private void Update()
{
m_playerCollider.height = Mathf.Max(m_playerCollider.radius, m_head.localPosition.y);
m_playerCollider.center = new Vector3(m_head.localPosition.x, m_head.localPosition.y / 2, m_head.localPosition.z);
}
}
} |