campfire/Assets/SteamVR/InteractionSystem/Core/Scripts/BodyCollider.cs
2020-04-29 20:40:05 +03:00

36 lines
1020 B
C#

//======= 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;
}
}
}