Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

35 lines
1020 B

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