holopy3/Assets/SteamVR/InteractionSystem/Core/Scripts/BodyCollider.cs

36 lines
1,020 B
C#
Raw Normal View History

2020-12-10 14:25:12 +00:00
//======= Copyright (c) Valve Corporation, All rights reserved. ===============
//
// Purpose: Collider dangling from the player's head
//
//=============================================================================
using UnityEngine;
using System.Collections;
namespace Valve.VR.InteractionSystem
{
//-------------------------------------------------------------------------
[RequireComponent( typeof( CapsuleCollider ) )]
public class BodyCollider : MonoBehaviour
{
public Transform head;
private CapsuleCollider capsuleCollider;
//-------------------------------------------------
void Awake()
{
capsuleCollider = GetComponent<CapsuleCollider>();
}
//-------------------------------------------------
void FixedUpdate()
{
float distanceFromFloor = Vector3.Dot( head.localPosition, Vector3.up );
capsuleCollider.height = Mathf.Max( capsuleCollider.radius, distanceFromFloor );
transform.localPosition = head.localPosition - 0.5f * distanceFromFloor * Vector3.up;
}
}
}