Skip to content

Instantly share code, notes, and snippets.

@ajmwagar
Created December 9, 2017 23:37
Show Gist options
  • Save ajmwagar/3c79c7d7e84a7d9f6e6990f781255195 to your computer and use it in GitHub Desktop.
Save ajmwagar/3c79c7d7e84a7d9f6e6990f781255195 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections.Generic;
public class Controls : MonoBehaviour {
// This
public RaycastHit lastRaycastHit;
public LayerMask teleportLayer;
public GameObject player;
public Camera cam;
// Controller
private SteamVR_TrackedObject trackedObj;
private SteamVR_Controller.Device Controller
{
get { return SteamVR_Controller.Input((int)trackedObj.index); }
}
private GameObject GazePoint()
{
Vector3 origin = this.player.transform.position;
Vector3 direction = this.cam.transform.forward;
float range = 200;
if (Physics.Raycast(origin, direction, out lastRaycastHit, range, teleportLayer.value)){
return lastRaycastHit.collider.gameObject;
}
else {
return null;
}
}
void Awake()
{
trackedObj = GetComponent<SteamVR_TrackedObject>();
}
void Start (){
}
void FixedUpdate () {
if (Controller.GetPressDown(SteamVR_Controller.ButtonMask.Axis1) || Controller.GetPressDown(SteamVR_Controller.ButtonMask.Axis0) || Controller.GetPressDown(SteamVR_Controller.ButtonMask.Axis3) || Controller.GetPressDown(SteamVR_Controller.ButtonMask.Axis4))
{
this.teleport();
}
}
public void teleport ()
{
this.player.transform.position = lastRaycastHit.point + lastRaycastHit.normal * 2;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment