IMHOTEP Framework
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Pages
BodyCollider.cs
1 //======= Copyright (c) Valve Corporation, All rights reserved. ===============
2 //
3 // Purpose: Collider dangling from the player's head
4 //
5 //=============================================================================
6 
7 using UnityEngine;
8 using System.Collections;
9 
10 namespace Valve.VR.InteractionSystem
11 {
12  //-------------------------------------------------------------------------
13  [RequireComponent( typeof( CapsuleCollider ) )]
14  public class BodyCollider : MonoBehaviour
15  {
16  public Transform head;
17 
18  private CapsuleCollider capsuleCollider;
19 
20  //-------------------------------------------------
21  void Awake()
22  {
23  capsuleCollider = GetComponent<CapsuleCollider>();
24  }
25 
26 
27  //-------------------------------------------------
28  void FixedUpdate()
29  {
30  float distanceFromFloor = Vector3.Dot( head.localPosition, Vector3.up );
31  capsuleCollider.height = Mathf.Max( capsuleCollider.radius, distanceFromFloor );
32  transform.localPosition = head.localPosition - 0.5f * distanceFromFloor * Vector3.up;
33  }
34  }
35 }