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 }); }