- Home /
In VR, how do I not let the reticle go beyond the far clipping plane?
I'm following a VR course (Become a VR Developer with Unity 3D - Lee Wasilenko) and I just made a reticle that's attached to your eyes. It works great and it changes sizes depending on how far away/close objects are. But when I look into the sky box it immediately goes to the default 3 meters in front of me, which is an annoying jump. How could I look to the far clipping plane and have the reticle not go any further away than that?
Here's my current script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Reticle : MonoBehaviour
{
[SerializeField]
private float defaultDistance = 3f;
public Transform reticleImageTransform;
public Transform trackedPointer;
private float Camera.main.farClipPlane;
private Vector3 originalScale;
private Vector3 farClipPlane;
void Start()
{
originalScale = reticleImageTransform.localScale;
Camera.main.farClipPlane = GetComponent<Camera.>()
}
public void SetPosition()
{
reticleImageTransform.position = trackedPointer.position + trackedPointer.forward * defaultDistance;
reticleImageTransform.localScale = originalScale;
}
public void SetPosition(RaycastHit hit)
{
reticleImageTransform.position = hit.point;
reticleImageTransform.localScale = originalScale * hit.distance;
if (reticleImageTransform.position > Camera.main.farClipPlane)
{
reticleImageTransform.position = 1f - Camera.main.farClipPlane;
}
}
}
Sorry if my question doesn't make a ton of sense, I'm a COMPLETE noob at coding.
Thanks!!!
From your code, I don't see where the SetPosition is called, but it looks like it has two versions; one that sets the reticle at a "default" position and one that sets it at the position of a raycast hit point. Ostensibly, the latter is called when a hit is detected and the former when the raycast misses.
Can't you just change the defaultDistance member to be the Camera far plane distance? Of course, you'd have to change the originalScale value as well.
Another option would be to just disable the reticle when there's no hit.
Your answer
![](https://koobas.hobune.stream/wayback/20220612123726im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Can Unity Remote 5 be used with GearVR development? 1 Answer
Windows MR Single Pass View Upside Down - 2018.0.2b7 2 Answers
[VR] Single Pass Instancing results in weird behavior per eye 0 Answers
How can i run a Unity Build on my PC, but use my phone as second screen, (Cheapskate Oculus-Like) 2 Answers
How to make UNITY multiplayer with two HTC VIVE in the same real room? 0 Answers