Skip to content

Instantly share code, notes, and snippets.

@scottyob
Created January 12, 2019 11:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottyob/776ae1b6b2dc993bde1418383c478aeb to your computer and use it in GitHub Desktop.
Save scottyob/776ae1b6b2dc993bde1418383c478aeb to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class VRTK_CursorMouse : VRTK.VRTK_StraightPointerRenderer {
public Camera camera;
public Transform hand;
protected override Transform GetOrigin(bool smoothed = true) {
return camera.transform;
}
protected override float CastRayForward()
{
RaycastHit hit;
Ray pointerRaycast = camera.ScreenPointToRay(Input.mousePosition);
Transform origin = GetOrigin();
RaycastHit pointerCollidedWith;
bool rayHit = VRTK.VRTK_CustomRaycast.Raycast(customRaycast, pointerRaycast, out pointerCollidedWith, defaultIgnoreLayer, maximumLength);
if (pointerCollidedWith.collider)
{
hand.LookAt(pointerCollidedWith.point);
}
else
{
hand.localRotation = Quaternion.identity;
}
CheckRayMiss(rayHit, pointerCollidedWith);
CheckRayHit(rayHit, pointerCollidedWith);
float actualLength = maximumLength;
if (rayHit && pointerCollidedWith.distance < maximumLength)
{
actualLength = pointerCollidedWith.distance;
}
return OverrideBeamLength(actualLength);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment