private bool UserIsOnNavMesh(StepByStepComponent sbs, TeleportNavMesh tnm, VRRaycastOutputs raycastOutputs, LayerMask excludedLayers, out float3 newCameraRigPos) { Transform vrCamTransform = VRSF_Components.VRCamera.transform; Transform cameraRigTransform = VRSF_Components.CameraRig.transform; // We calculate the direction and the distance Vectors var directionVector = raycastOutputs.RayVar.direction; float distanceVector = cameraRigTransform.localScale.y * sbs.DistanceStepByStep; // Check if we hit a collider on the way. If it's the case, we reduce the distance. if (Physics.Raycast(vrCamTransform.position, directionVector, out RaycastHit hit, distanceVector, ~excludedLayers)) { distanceVector = hit.distance - 0.1f; } // We multiply the direction vector by the distance to which the user should be going directionVector *= distanceVector; // We check the theoritic position for the cameraRig newCameraRigPos = GetNewTheoriticPos(directionVector, true); // We check the theoritic new user pos float3 newCameraPos = GetNewTheoriticPos(directionVector, false); // We calculate a vector down based on the new Camera Pos. var downVectorDistance = Mathf.Abs(vrCamTransform.localPosition.y + VRSF_Components.FloorOffset.transform.localPosition.y) + sbs.StepHeight; var downVector = newCameraPos + (new float3(0.0f, -1.0f, 0.0f) * downVectorDistance); // We calculate the linecast between the newUserPos and the downVector and check if it hits the NavMesh TeleportNavMeshHelper.Linecast ( newCameraPos, downVector, out bool endOnNavmesh, excludedLayers, out newCameraPos, out _, tnm ); // We set the camera rig pos in y to the camera pos in y newCameraRigPos.y = newCameraPos.y; return(endOnNavmesh); /// <summary> /// We get the theoritic position for the CameraRig and the VRCamera based on the scaled direction (direction * distance) /// </summary> /// <param name="scaledDirection">The direction multiplied by the distance to go to</param> /// <param name="isCheckingCameraRig">Whether the check is for the CameraRig or the VRCamera</param> /// <returns>The new Theoritic position</returns> float3 GetNewTheoriticPos(Vector3 scaledDirection, bool isCheckingCameraRig) { float3 origin = isCheckingCameraRig ? cameraRigTransform.position : vrCamTransform.position; return(origin + new float3(scaledDirection.x, 0.0f, scaledDirection.z)); } }
private float3 CheckEndPoint(LaserPointerLength laserLength, VRRaycastOutputs raycastOutputs) { if (raycastOutputs.RaycastHitVar.Value.collider != null && raycastOutputs.RaycastHitVar.Value.collider.gameObject.layer == _uiLayer) { return(laserLength.ShouldPointToUICenter ? (float3)raycastOutputs.RaycastHitVar.Value.collider.bounds.center : (float3)raycastOutputs.RaycastHitVar.Value.point); } else { return(laserLength.ShouldPointTo3DObjectsCenter ? (float3)raycastOutputs.RaycastHitVar.Value.collider.bounds.center : (float3)raycastOutputs.RaycastHitVar.Value.point); } }
private bool RaycastedObjectIsntUI(VRRaycastOutputs raycastOutputs) { return(raycastOutputs.RaycastHitVar.IsNull || raycastOutputs.RaycastHitVar.Value.collider.gameObject.layer != LayerMask.NameToLayer("UI")); }