private void UpdateArc()
    {
        if (SteamVR_Actions.default_TouchPad[SteamVR_Input_Sources.RightHand].axis == Vector2.zero)
        {
            if (IsArcActive)
            {
                _arc.Hide();
                _teleportMarker.SetAlpha(0f, 0f);
            }
            IsArcActive = false;
            return;
        }

        IsArcActive = true;
        Vector3 arcVelocity = _aimAnchor.forward * _maxDistance;

        _arc.SetArcData(_aimAnchor.position, arcVelocity, true, false);

        bool didHit = _arc.DrawArc(out RaycastHit hit);

        if (didHit)
        {
            _arcTarget        = hit.point;
            _isArcTargetValid = true;
            _arc.SetColor(Color.green);

            _teleportMarker.transform.position = hit.point;
            _log.Append("origTarget", hit.point);

            Vector3 markerPos;
            if (_markerCollider.HasCollided())
            {
                markerPos   = _markerCollider.GetAdjustedPosition();
                markerPos.y = hit.point.y;
                _teleportMarker.transform.position = markerPos;

                _log.Append("shiftedTarget", markerPos);
            }

            _teleportMarker.SetAlpha(1f, 1f);
        }

        if (!didHit || hit.collider.gameObject.layer != 12)
        {
            _arc.SetColor(Color.red);
            _teleportMarker.SetAlpha(0f, 0f);
            _isArcTargetValid = false;
        }
        _arc.Show();
        _log.Append("targetValid", _isArcTargetValid);
    }
Exemple #2
0
    private void UpdateArc()
    {
        //Vector3 arcPos = startPos + (projectileVelocity * time) + (0.5 * time * time) * gravity = grabOject.gameObject.transform.position;
        Vector3 gravity            = Physics.gravity;
        Vector3 projectileVelocity = (grabObject.transform.position - transform.position - 0.5f * gravity);

        //Vector3 diff = transform.position - grabObject.gameObject.transform.position;
        //Vector3 velocity = transform.forward * diff.magnitude;
        teleportArc.SetArcData(transform.position, projectileVelocity, true, false);
        RaycastHit hit;

        teleportArc.DrawArc(out hit);
        teleportArc.SetColor(Color.cyan);

        teleportArc.Show();
    }
Exemple #3
0
    //Vector3 a, b = new Vector3();

    void Update()
    {
        hit = new RaycastHit();
        if (teleportAction.GetState(controller))
        {
            if (!arc.gameObject.activeSelf)
            {
                arc.gameObject.SetActive(true);
            }
            canTeleport = DoTeleportCheck();
            Color c = canTeleport? Color.cyan: Color.red;
            arc.SetColor(c);
            downLine.startColor = c;
            downLine.endColor   = c;
        }
        else if (teleportAction.GetStateUp(controller) && !snapTurnLeft.GetState(controller) && !snapTurnRight.GetState(controller))
        {
            //teleport here
            if (canTeleport)
            {
                //Debug.Log("teleporting");

                //teleport with offset
                body.position += (teleportVector + (Vector3.up * 0.1f));
            }
            arc.gameObject.SetActive(false);
            downLine.SetPosition(0, Vector3.zero);
            downLine.SetPosition(1, Vector3.zero);
        }

        if ((snapTurnLeft.GetState(controller) || snapTurnRight.GetState(controller)))
        {
            arc.gameObject.SetActive(false);
            downLine.SetPosition(0, Vector3.zero);
            downLine.SetPosition(1, Vector3.zero);
        }
    }
Exemple #4
0
    //-------------------------------------------------
    private void UpdatePointer()
    {
        Vector3 pointerStart = pointerStartTransform.position;
        Vector3 pointerEnd;
        Vector3 pointerDir          = pointerStartTransform.forward;
        bool    hitSomething        = false;
        bool    showPlayAreaPreview = false;
        //Vector3 playerFeetOffset = player.trackingOriginTransform.position - player.feetPositionGuess;
        Vector3 playerFeetOffset = player.transform.position - player.feetPositionGuess;

        Vector3 arcVelocity = pointerDir * arcDistance;

        TeleportMarkerBase hitTeleportMarker = null;

        //Check pointer angle
        float dotUp = Vector3.Dot(pointerDir, Vector3.up);
        //NVRReplace//float dotForward = Vector3.Dot( pointerDir, player.hmdTransform.forward );
        float dotForward        = Vector3.Dot(pointerDir, player.Head.transform.forward);
        bool  pointerAtBadAngle = false;

        if ((dotForward > 0 && dotUp > 0.75f) || (dotForward < 0.0f && dotUp > 0.5f))
        {
            pointerAtBadAngle = true;
        }

        //Trace to see if the pointer hit anything
        RaycastHit hitInfo;

        teleportArc.SetArcData(pointerStart, arcVelocity, true, pointerAtBadAngle);
        if (teleportArc.DrawArc(out hitInfo))
        {
            hitSomething      = true;
            hitTeleportMarker = hitInfo.collider.GetComponentInParent <TeleportMarkerBase>();
        }

        if (pointerAtBadAngle)
        {
            hitTeleportMarker = null;
        }

        HighlightSelected(hitTeleportMarker);

        if (hitTeleportMarker != null)                   //Hit a teleport marker
        {
            if (hitTeleportMarker.locked)
            {
                teleportArc.SetColor(pointerLockedColor);
                                        #if (UNITY_5_4)
                pointerLineRenderer.SetColors(pointerLockedColor, pointerLockedColor);
                                        #else
                pointerLineRenderer.startColor = pointerLockedColor;
                pointerLineRenderer.endColor   = pointerLockedColor;
                                        #endif
                destinationReticleTransform.gameObject.SetActive(false);
            }
            else
            {
                teleportArc.SetColor(pointerValidColor);
                                        #if (UNITY_5_4)
                pointerLineRenderer.SetColors(pointerValidColor, pointerValidColor);
                                        #else
                pointerLineRenderer.startColor = pointerValidColor;
                pointerLineRenderer.endColor   = pointerValidColor;
                                        #endif
                destinationReticleTransform.gameObject.SetActive(hitTeleportMarker.showReticle);
            }

            offsetReticleTransform.gameObject.SetActive(true);

            invalidReticleTransform.gameObject.SetActive(false);

            pointedAtTeleportMarker = hitTeleportMarker;
            pointedAtPosition       = hitInfo.point;

            if (showPlayAreaMarker)
            {
                //Show the play area marker if this is a teleport area
                VHONTeleportArea teleportArea = pointedAtTeleportMarker as VHONTeleportArea;
                if (teleportArea != null && !teleportArea.locked && playAreaPreviewTransform != null)
                {
                    Vector3 offsetToUse = playerFeetOffset;

                    //Adjust the actual offset to prevent the play area marker from moving too much
                    if (!movedFeetFarEnough)
                    {
                        float distanceFromStartingOffset = Vector3.Distance(playerFeetOffset, startingFeetOffset);
                        if (distanceFromStartingOffset < 0.1f)
                        {
                            offsetToUse = startingFeetOffset;
                        }
                        else if (distanceFromStartingOffset < 0.4f)
                        {
                            offsetToUse = Vector3.Lerp(startingFeetOffset, playerFeetOffset, (distanceFromStartingOffset - 0.1f) / 0.3f);
                        }
                        else
                        {
                            movedFeetFarEnough = true;
                        }
                    }

                    playAreaPreviewTransform.position = pointedAtPosition + offsetToUse;

                    showPlayAreaPreview = true;
                }
            }

            pointerEnd = hitInfo.point;
        }
        else                 //Hit neither
        {
            destinationReticleTransform.gameObject.SetActive(false);
            offsetReticleTransform.gameObject.SetActive(false);

            teleportArc.SetColor(pointerInvalidColor);
#if (UNITY_5_4)
            pointerLineRenderer.SetColors(pointerInvalidColor, pointerInvalidColor);
#else
            pointerLineRenderer.startColor = pointerInvalidColor;
            pointerLineRenderer.endColor   = pointerInvalidColor;
#endif
            invalidReticleTransform.gameObject.SetActive(!pointerAtBadAngle);

            //Orient the invalid reticle to the normal of the trace hit point
            Vector3 normalToUse = hitInfo.normal;
            float   angle       = Vector3.Angle(hitInfo.normal, Vector3.up);
            if (angle < 15.0f)
            {
                normalToUse = Vector3.up;
            }
            invalidReticleTargetRotation     = Quaternion.FromToRotation(Vector3.up, normalToUse);
            invalidReticleTransform.rotation = Quaternion.Slerp(invalidReticleTransform.rotation, invalidReticleTargetRotation, 0.1f);

            //Scale the invalid reticle based on the distance from the player
            //NVRReplace//float distanceFromPlayer = Vector3.Distance( hitInfo.point, player.hmdTransform.position );
            float distanceFromPlayer         = Vector3.Distance(hitInfo.point, player.Head.transform.position);
            float invalidReticleCurrentScale = Util.RemapNumberClamped(distanceFromPlayer, invalidReticleMinScaleDistance, invalidReticleMaxScaleDistance, invalidReticleMinScale, invalidReticleMaxScale);
            invalidReticleScale.x = invalidReticleCurrentScale;
            invalidReticleScale.y = invalidReticleCurrentScale;
            invalidReticleScale.z = invalidReticleCurrentScale;
            invalidReticleTransform.transform.localScale = invalidReticleScale;

            pointedAtTeleportMarker = null;

            if (hitSomething)
            {
                pointerEnd = hitInfo.point;
            }
            else
            {
                pointerEnd = teleportArc.GetArcPositionAtTime(teleportArc.arcDuration);
            }

            //Debug floor
            if (debugFloor)
            {
                floorDebugSphere.gameObject.SetActive(false);
                floorDebugLine.gameObject.SetActive(false);
            }
        }

        if (playAreaPreviewTransform != null)
        {
            playAreaPreviewTransform.gameObject.SetActive(showPlayAreaPreview);
        }

        if (!showOffsetReticle)
        {
            offsetReticleTransform.gameObject.SetActive(false);
        }

        destinationReticleTransform.position = pointedAtPosition;
        invalidReticleTransform.position     = pointerEnd;
        onActivateObjectTransform.position   = pointerEnd;
        onDeactivateObjectTransform.position = pointerEnd;
        offsetReticleTransform.position      = pointerEnd - playerFeetOffset;

        reticleAudioSource.transform.position = pointedAtPosition;

        pointerLineRenderer.SetPosition(0, pointerStart);
        pointerLineRenderer.SetPosition(1, pointerEnd);
    }
    private void UpdatePointer()
    {
        if (Controller.GetAxis().y - trackPadStart.y > .2)
        {
            teleport = true;
        }
        else
        {
            teleport = false;
        }
        Vector3 pointerStart = trackedObj.transform.position;
        Vector3 pointerEnd;
        Vector3 pointerDir       = trackedObj.transform.forward;
        bool    hitSomething     = false;
        Vector3 playerFeetOffset = playerTrackingOriginTransform.position - feetPositionGuess;

        Vector3 arcVelocity = pointerDir * arcDistance;

        TeleportMarkerBase hitTeleportMarker = null;

        //Check pointer angle
        float dotUp             = Vector3.Dot(pointerDir, Vector3.up);
        float dotForward        = Vector3.Dot(pointerDir, playerHMD.transform.forward);
        bool  pointerAtBadAngle = false;

        if ((dotForward > 0 && dotUp > 0.75f) || (dotForward < 0.0f && dotUp > 0.5f))
        {
            pointerAtBadAngle = true;
        }

        //Trace to see if the pointer hit anything
        RaycastHit hitInfo;

        teleportArc.SetArcData(pointerStart, arcVelocity, true, pointerAtBadAngle);
        if (teleportArc.DrawArc(out hitInfo))
        {
            hitSomething      = true;
            hitTeleportMarker = hitInfo.collider.GetComponentInParent <TeleportMarkerBase>();
        }

        if (pointerAtBadAngle)
        {
            hitTeleportMarker = null;
        }

        if (teleport)
        {
            teleportArc.SetColor(pointerTeleportColor);
            teleportPointMaterial.SetColor("_TintColor", pointerTeleportColor);
        }
        else
        {
            teleportArc.SetColor(pointerValidColor);
            teleportPointMaterial.SetColor("_TintColor", pointerValidColor);
        }


        /////////////////////////
        ////////////////////////
        ///////////////
        ////////////
        /////////
        ///////
        /////////////////LOOK AT teleportPointerObject for line color

        invalidReticleTransform.gameObject.SetActive(!pointerAtBadAngle);

        //Orient the invalid reticle to the normal of the trace hit point
        Vector3 normalToUse = hitInfo.normal;
        float   angle       = Vector3.Angle(hitInfo.normal, Vector3.up);

        if (angle < 15.0f)
        {
            normalToUse = Vector3.up;
        }

        float distanceFromPlayer = Vector3.Distance(hitInfo.point, playerHMD.transform.position);

        if (hitSomething)
        {
            pointerEnd = hitInfo.point;
        }
        else
        {
            pointerEnd = teleportArc.GetArcPositionAtTime(teleportArc.arcDuration);
        }

        invalidReticleTransform.position = pointerEnd;

        //pointerLineRenderer.SetPosition(0, pointerStart);
        // pointerLineRenderer.SetPosition(1, pointerEnd);
    }