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

36 lines
1020 B
C#
Raw Permalink Normal View History

2020-04-29 19:40:05 +02: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;
}
}
}