Created
June 12, 2020 19:34
-
-
Save lordlycastle/758a5f7f560d06b7a794c67dfed702e1 to your computer and use it in GitHub Desktop.
Add moving stuff as child with Z offset which will be distance from headset. Use this to rotate the root gameobject.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using DG.Tweening; | |
using Sirenix.OdinInspector; | |
using UnityEngine; | |
public class MoveItemToView : MonoBehaviour | |
{ | |
[Header("Found dynamically.")] | |
public Transform headsetTransform; | |
public GameObject itemParent; | |
private void Start () | |
{ | |
DOTween.Sequence() | |
.SetDelay(0.1f) | |
.AppendCallback(() => | |
{ | |
if (itemParent) | |
{ | |
itemParent = gameObject; | |
} | |
headsetTransform = VRTK.VRTK_DeviceFinder.HeadsetTransform(); | |
itemParent.transform.position = headsetTransform.position; | |
}) | |
.Play(); | |
} | |
void Update () | |
{ | |
if (headsetTransform == null) | |
return; | |
var newAngle = Quaternion.LerpUnclamped(itemParent.transform.rotation, | |
headsetTransform.rotation, Time.deltaTime); | |
itemParent.transform.rotation = newAngle; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment