- Home /
Question by
EmilLundgrenVR17 · Apr 03, 2019 at 01:50 PM ·
raycastvr
VRTK_Pointer Raycast Quaternion
Hello
I have a scene in Unity where I would like a Gameobject to look at the end of the Raycast from the controller in VR. I have a working code that works if the "Target" to look at is another gameobject.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using VRTK;
public class SlerpToLookAt : MonoBehaviour
{
VRTK_Pointer pointer;
//values that will be set in the Inspector
public Transform Target;
public float RotationSpeed;
void Start()
{
pointer = GetComponent<VRTK_Pointer>();
}
//values for internal use
private Quaternion _lookRotation;
private Vector3 _direction;
// Update is called once per frame
void Update()
{
//find the vector pointing from our position to the target
_direction = (Target.position - transform.position).normalized;
//create the rotation we need to be in to look at the target
_lookRotation = Quaternion.LookRotation(_direction);
//rotate us over time according to speed until we are in the required rotation
transform.rotation = Quaternion.Slerp(transform.rotation, _lookRotation, Time.deltaTime * RotationSpeed);
}
}
How can I modify this code so It looks at the RaycastHit from VRTK instead of the "Public Transform Target;"?
Thank you for your time!
Have a nice day
Comment
Your answer
Follow this Question
Related Questions
ScreenToRayPoint not working in VR, how to substitute? 0 Answers
XR Interactor not detecting object in my inventory script and idk why. 0 Answers
Worldspace Scroll View with Buttons in VR (Gear) 0 Answers
Destroy object after time Only if raycast is colliding; 0 Answers
How to access menu button in vive by using steamvr player 1 Answer