Skip to content

Instantly share code, notes, and snippets.

@pjc0247
Created July 30, 2017 15:12
Show Gist options
  • Save pjc0247/74167dcdc02d62b0b237a5c2b178b9cd to your computer and use it in GitHub Desktop.
Save pjc0247/74167dcdc02d62b0b237a5c2b178b9cd to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using NewtonVR;
public class FollowingHUD : MonoBehaviour {
public enum FollowingType
{
/// <summary>바로바로 따라옴</summary>
Immediate,
/// <summary>등속 이동</summary>
Uniform,
/// <summary>비등속 이동</summary>
Accel
}
public float distanceFromEye = 5;
public float uniformSpeed = 2;
public float accelSpeed = 0.12f;
public FollowingType type = FollowingType.Accel;
void LateUpdate () {
var head = NVRPlayer.Instance.Head;
transform.eulerAngles = head.transform.eulerAngles;
if (type == FollowingType.Immediate)
transform.position = GetTargetPosition();
else if (type == FollowingType.Accel)
transform.position += (GetTargetPosition() - transform.position) * accelSpeed;
else
{
var diff = (GetTargetPosition() - transform.position);
var diffNorm = diff.normalized;
if (diff.sqrMagnitude <= 0.01f) return;
transform.position += diffNorm * Time.deltaTime * uniformSpeed;
}
}
private Vector3 GetTargetPosition()
{
var head = NVRPlayer.Instance.Head;
return head.transform.position + head.transform.forward * distanceFromEye;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment