// Update is called once per frame void LateUpdate() { Line.enabled = false; if (handScript.UseButtonPressed) { Line.enabled = true; Line.material.SetColor("_Color", LineColor); NVRHelpers.LineRendererSetColor(Line, LineColor, LineColor); NVRHelpers.LineRendererSetWidth(Line, LineWidth, LineWidth); RaycastHit hitInfo; bool hit = Physics.Raycast(this.transform.position, this.transform.forward, out hitInfo, 1000); Vector3 endPoint; if (hit == true) { endPoint = hitInfo.point; GameObject hitObject = hitInfo.collider.gameObject; if (hitObject.CompareTag("Interactable")) { hitObject.transform.position = transform.position; hitObject.GetComponent <Rigidbody>().velocity = Vector2.zero; } } else { endPoint = this.transform.position + (this.transform.forward * 1000f); } Line.SetPositions(new Vector3[] { this.transform.position, endPoint }); } }
private void LateUpdate() { Line.enabled = ForceLineVisible || (OnlyVisibleOnTrigger && Hand != null && Hand.Inputs[NVRButtons.Trigger].IsPressed); if (Line.enabled == true) { Line.material.SetColor("_Color", LineColor); NVRHelpers.LineRendererSetColor(Line, LineColor, LineColor); NVRHelpers.LineRendererSetWidth(Line, LineWidth, LineWidth); RaycastHit hitInfo; bool hit = Physics.Raycast(this.transform.position, this.transform.forward, out hitInfo, 1000); Vector3 endPoint; if (hit == true) { endPoint = hitInfo.point; } else { endPoint = this.transform.position + (this.transform.forward * 1000f); } Line.SetPositions(new Vector3[] { this.transform.position, endPoint }); } }
void Awake() { Line = this.gameObject.AddComponent <LineRenderer>(); Line.material = new Material(Shader.Find("Unlit/Color")); Line.material.SetColor("_Color", LineColor); NVRHelpers.LineRendererSetColor(Line, LineColor, LineColor); Line.useWorldSpace = true; Line.enabled = false; }
private void InitPointer() { Pointer = this.GetComponent <LineRenderer>(); if (Pointer == null) { Pointer = this.gameObject.AddComponent <LineRenderer>(); } if (Pointer.sharedMaterial == null) { Pointer.material = new Material(Shader.Find("Unlit/Color")); Pointer.material.SetColor("_Color", PointerColor); NVRHelpers.LineRendererSetColor(Pointer, PointerColor, PointerColor); } Pointer.useWorldSpace = true; }
private void LateUpdate() { Line.enabled = (Hand != null && Hand.Inputs[NVRButtons.Trigger].SingleAxis > 0.01f); if (Line.enabled == true) { Line.material.SetColor("_Color", LineColor); NVRHelpers.LineRendererSetColor(Line, LineColor, LineColor); NVRHelpers.LineRendererSetWidth(Line, LineWidth, LineWidth); RaycastHit hitInfo; bool hit = Physics.Raycast(this.transform.position, this.transform.forward, out hitInfo, 1000); Vector3 endPoint; if (hit == true) { endPoint = hitInfo.point; if (Hand.Inputs[NVRButtons.Trigger].PressDown == true) { NVRInteractable LHandInteractable = Player.LeftHand.CurrentlyInteracting; NVRInteractable RHandInteractable = Player.RightHand.CurrentlyInteracting; Vector3 offset = Player.Head.transform.position - Player.transform.position; offset.y = 0; Player.transform.position = hitInfo.point - offset; if (LHandInteractable != null) { LHandInteractable.transform.position = Player.LeftHand.transform.position; } if (RHandInteractable != null) { RHandInteractable.transform.position = Player.RightHand.transform.position; } } } else { endPoint = this.transform.position + (this.transform.forward * 1000f); } Line.SetPositions(new Vector3[] { this.transform.position, endPoint }); } }
private void Awake() { Line = this.GetComponent <LineRenderer>(); Hand = this.GetComponent <NVRHand>(); if (Line == null) { Line = this.gameObject.AddComponent <LineRenderer>(); } if (Line.sharedMaterial == null) { Line.material = new Material(Shader.Find("Unlit/Color")); Line.material.SetColor("_Color", LineColor); NVRHelpers.LineRendererSetColor(Line, LineColor, LineColor); } Line.useWorldSpace = true; }
private void LateUpdate() { Line.enabled = (Hand != null && Hand.Inputs[LaserEnableButton].SingleAxis > 0.01f); if (Line.enabled == true) { Line.material.SetColor("_Color", LineColor); NVRHelpers.LineRendererSetColor(Line, LineColor, LineColor); NVRHelpers.LineRendererSetWidth(Line, LineWidth, LineWidth); RaycastHit hitInfo; bool hit = Physics.Raycast(this.transform.position, this.transform.forward, out hitInfo, 1000); Vector3 endPoint = transform.position; if (hit == true) { // TODO: Display marker at hit location endPoint = hitInfo.point; bool isInLayer; if (RestrictToLayer) { isInLayer = ((Layer & 1 << hitInfo.transform.gameObject.layer) == 1 << hitInfo.transform.gameObject.layer); } else { isInLayer = true; } if (hitInfo.distance <= MaxTeleportDistance && isInLayer) { if (Hand.Inputs[TeleportButton].PressDown == true) { NVRInteractable LHandInteractable = Player.LeftHand.CurrentlyInteracting; NVRInteractable RHandInteractable = Player.RightHand.CurrentlyInteracting; Vector3 offset = Player.Head.transform.position - Player.transform.position; offset.y = 0; Player.transform.position = hitInfo.point - offset; if (LHandInteractable != null) { LHandInteractable.transform.position = Player.LeftHand.transform.position; } if (RHandInteractable != null) { RHandInteractable.transform.position = Player.RightHand.transform.position; } } } } else { endPoint = this.transform.position + (this.transform.forward * 1000f); } Line.SetPositions(new Vector3[] { this.transform.position, endPoint }); } }
private void UpdatePointer() { //TODO is this necessary here? Pointer.material.SetColor("_Color", PointerColor); NVRHelpers.LineRendererSetColor(Pointer, PointerColor, PointerColor); NVRHelpers.LineRendererSetWidth(Pointer, PointerWidth, PointerWidth); pointerOrigin = transform.position; //TODO fix pointer angle pointerTarget = transform.forward; ghostCellPrefab.SetActive(false); RaycastHit hitInfo; bool hit = Physics.Raycast(pointerOrigin, pointerTarget, out hitInfo, 1000); Vector3 endPoint; if (hit == true) { //1.01 extends the ray slightly to avoid landing on a hex boundary endPoint = hitInfo.point * 1.01f; if (pointerTracker != null) { pointerTracker.transform.position = endPoint; } //Check if we hit a terrain chunk GameObject hitObjectParent = hitInfo.transform.parent.gameObject; TerrainChunk hitChunk = hitObjectParent.GetComponent <TerrainChunk>(); if (hitChunk) { HexCoordinates worldCoordinates = HexCoordinates.WorldCoordsFromGlobalPosition(terrain, endPoint); Vector2 worldOffset = worldCoordinates.ToOffsetCoordinates(); this.TouchCell(hitChunk, worldCoordinates); //If button is clicked, edit chunk if (clicked) { clicked = false; if (objectType == TerrainObjectType.Cell) { if (cellType == CellType.Missing && hitChunk.CanRemoveCell(worldCoordinates)) { hitChunk.RemoveTerrainObject(worldCoordinates); hitChunk.RemoveCell(worldCoordinates); } else { hitChunk.RemoveTerrainObject(worldCoordinates); hitChunk.AddCell(cellType, worldCoordinates); } } else { if (objectType == TerrainObjectType.Missing) { hitChunk.RemoveTerrainObject(worldCoordinates); } else { hitChunk.AddTerrainObject(objectType, worldCoordinates); } } //Send pulse to controller if terraform was successful InputController inputController = FindObjectOfType <InputController>(); if (inputController) { inputController.TriggerPrimaryHandPulse(); } } } } else { //If we missed, extend the pointer out in a straight line endPoint = pointerOrigin + (pointerTarget * 1000f); } Pointer.SetPositions(new Vector3[] { pointerOrigin, endPoint }); }
private void LateUpdate() { var controller = GetComponent <SteamVR_TrackedController>(); Line.enabled = controller.triggerPressed; controller.TriggerClicked += teleport; if (Line.enabled) { // Draw Line // Check if can teleport, when we can, add teleport to trigger clicked } if (Line.enabled == true) { Line.material.SetColor("_Color", LineColor); NVRHelpers.LineRendererSetColor(Line, LineColor, LineColor); NVRHelpers.LineRendererSetWidth(Line, LineWidth, LineWidth); RaycastHit hitInfo; bool hit = Physics.Raycast(this.transform.position, this.transform.forward, out hitInfo, 1000); Vector3 endPoint = transform.position; if (hit == true) { // TODO: Display marker at hit location endPoint = hitInfo.point; bool isInLayer; if (RestrictToLayer) { isInLayer = ((Layer & 1 << hitInfo.transform.gameObject.layer) == 1 << hitInfo.transform.gameObject.layer); } else { isInLayer = true; } if (hitInfo.distance <= MaxTeleportDistance && isInLayer) { if (true) // Hand.Inputs[TeleportButton].PressDown == true) { NVRInteractable LHandInteractable = Player.LeftHand.CurrentlyInteracting; NVRInteractable RHandInteractable = Player.RightHand.CurrentlyInteracting; Vector3 offset = Player.Head.transform.position - Player.transform.position; offset.y = 0; Player.transform.position = hitInfo.point - offset; if (LHandInteractable != null) { LHandInteractable.transform.position = Player.LeftHand.transform.position; } if (RHandInteractable != null) { RHandInteractable.transform.position = Player.RightHand.transform.position; } } } } else { endPoint = this.transform.position + (this.transform.forward * 1000f); } Line.SetPositions(new Vector3[] { this.transform.position, endPoint }); } }