private bool ControllerRaycast(out Vector3 hitPoint) { Ray ray = new Ray(m_controllerEvents.transform.position, transform.forward); RaycastHit hit; if (VRTK_CustomRaycast.Raycast(m_customRaycast, ray, out hit, m_layersToIgnore, m_maxDistance)) { hitPoint = hit.point; if (m_coneDrag) { Vector3 groundPos = m_playArea.position; // find ground below play area RaycastHit groundHit; Ray groundRay = new Ray(new Vector3(groundPos.x, m_headset.position.y, groundPos.z), Vector3.down); if (VRTK_CustomRaycast.Raycast(m_customRaycast, groundRay, out groundHit, m_layersToIgnore)) { groundPos = groundHit.point; } // a "ramp" m_plane = new Plane(groundPos, hitPoint, groundPos + Vector3.Cross(Vector3.up, hitPoint - groundPos)); } else { m_plane = new Plane(Vector3.up, hitPoint); } return(true); } hitPoint = Vector3.zero; return(false); }
private GameObject GetCollidedObject(out RaycastHit pointerCollidedWith) { Transform origin = GetOrigin(); Ray pointerRaycast = new Ray(origin.position, origin.forward); bool rayHit = VRTK_CustomRaycast.Raycast(customRaycast, pointerRaycast, out pointerCollidedWith, defaultIgnoreLayer, maximumLength); if (pointerCollidedWith.collider != null) { return(pointerCollidedWith.collider.gameObject); } else { return(null); } }
// Identical to VRTK_StraightPointerRenderer except we return actual ray length instead of truncated ray protected override float CastRayForward() { Transform origin = GetOrigin(); Ray pointerRaycast = new Ray(origin.position, origin.forward); RaycastHit pointerCollidedWith; customRaycast = new VRTK_CustomRaycast(); customRaycast.layersToIgnore = LayerMask.NameToLayer("Ignore Raycast"); #pragma warning disable 0618 bool rayHit = VRTK_CustomRaycast.Raycast(customRaycast, pointerRaycast, out pointerCollidedWith, layersToIgnore, maximumLength); #pragma warning restore 0618 CheckRayMiss(rayHit, pointerCollidedWith); CheckRayHit(rayHit, pointerCollidedWith); float actualLength = maximumLength; if (rayHit && pointerCollidedWith.distance < maximumLength) { actualLength = pointerCollidedWith.distance; } return(actualLength); }