Ejemplo n.º 1
0
    private void ThrowObject(LaserPonterReciever lpr)
    {
        // Transform cameraTransform = Camera.main.transform;
        Transform cameraTransform = Player.instance.hmdTransform;

        float handVelocity = Vector3.Dot(pose[Player.instance.rightHand.handType].velocity,
                                         (cameraTransform.forward - cameraTransform.up));

        // Debug.Log("Hand Velocity: " + handVelocity, this);

        if (handVelocity < -handVelocitySensitivity)
        {
            isMoving  = true;
            interrupt = false;

            switch (physicsToUse)
            {
            case NotRusselsPhysics.Velocity:
                UseVelocity(lpr);
                break;

            case NotRusselsPhysics.Bezier:
                StartCoroutine(UseBezierCurve(lpr));
                break;
            }
        }
    }
Ejemplo n.º 2
0
    private void RayChanged()
    {
        if (!oldLastHit)
        {
            return;
        }

        oldLastHit.ResetMat();
        oldLastHit      = lastHit;
        materialUpdated = false;
    }
Ejemplo n.º 3
0
    private void UseVelocity(LaserPonterReciever lpr)
    {
        Time.timeScale = 0.5f;

        //Calculate velocity and apply it to the target
        Vector3 velocity = RATSCalculations.CalculateParabola(lpr.gameObject.transform.position,
                                                              objectAttachmentPoint.position);
        Vector3 dampVelocity = Vector3.Scale(velocity, velocityDampening);

        // Debug.Log("Velocity: " + velocity);
        // Debug.Log("Dampened Velocity: " + dampVelocity);
        lpr.rigidbody.velocity = dampVelocity;
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Reset all necessary parameters when RATS are no longer pointing at an object.
    /// </summary>
    private void RayExit()
    {
        if (!lastHit)
        {
            return;
        }

        lastHit.RayExit();
        lastHit         = null;
        oldLastHit      = null;
        materialUpdated = false;
        // isMoving = false;
        Time.timeScale = 1;
    }
Ejemplo n.º 5
0
    private IEnumerator UseBezierCurve(LaserPonterReciever lpr)
    {
        float   step = 1;
        Vector3 peak = RATSCalculations.CalculateMidpoint(lpr.gameObject.transform, objectAttachmentPoint);

        peak += new Vector3(0, 1, 0);

        Vector3 start  = lpr.gameObject.transform.position;
        Vector3 target = objectAttachmentPoint.position;

        // Debug.LogWarning("Gravity off", this);
        lpr.rigidbody.useGravity  = false;
        lpr.rigidbody.isKinematic = true;
        lpr.moveToTarget          = true;
        lpr.interrupt             = false;
        nextStep = false;

        while (step <= bezierSteps && !interrupt)
        {
            // Debug.Log("Step: " + step + " || " + step / bezierSteps + " Start: " + start + " End: " + target +
            // " Current: " + lpr.gameObject.transform.position);

            nextStep = false;

            Vector3 newPos = RATSCalculations.CalculateQuadraticBezierCurves(start,
                                                                             peak, target, step / bezierSteps);
            lpr.target = newPos;
            step++;

            yield return(new WaitUntil(() => nextStep));
        }

        if (interrupt)
        {
            Debug.LogWarning("Interrupt", this);
        }
        else
        {
            // Debug.LogWarning("Gravity on", this);
            lpr.rigidbody.useGravity  = true;
            lpr.rigidbody.isKinematic = false;
        }

        // Debug.LogWarning("Moving finished", this);
        lpr.moveToTarget = false;
        isMoving         = false;
    }
Ejemplo n.º 6
0
    private void CalculateHit()
    {
        // The number of returned colliders is limited to this allocated buffer
        Collider[] colliders     = new Collider[AppData.BufferAllocation];
        int        noOfColliders = Physics.OverlapCapsuleNonAlloc(transform.position, endTarget.transform.position,
                                                                  radius, colliders, AppData.InteractableLayerMask);

        if (noOfColliders > 0)
        {
            // Debug.LogWarning("We got " + noOfColliders);
            Collider target = noOfColliders > 1 ? FindClosestTarget(colliders) : colliders[0];

            lastHit = target.transform.GetComponent <LaserPonterReciever>();

            if (!lastHit)
            {
                return;
            }

            if (!oldLastHit)
            {
                oldLastHit = lastHit;
            }
            else if (oldLastHit != lastHit)
            {
                RayChanged();
            }

            // Material update should only be called once per object
            if (!materialUpdated)
            {
                lastHit.HitByRay();
                materialUpdated = true;
            }

            if (IsClicking() && !isMoving)
            {
                ThrowObject(lastHit);
            }
        }
        else
        {
            RayExit();
        }
    }
Ejemplo n.º 7
0
    private void RayExit()
    {
        if (!lastHit)
        {
            return;
        }

        // Debug.Log("RayExit");

        lastHit.RayExit();
        lastHit = null;

        oldLastHit.ResetMat();
        oldLastHit = null;

        materialUpdated = false;
        wasClicked      = false;
    }
Ejemplo n.º 8
0
    private Vector3 CalculateEnd()
    {
        RaycastHit hit = CreateForwardRaycast();
        Vector3    endPosition;

        if (hit.collider)
        {
            endPosition = hit.point;
            lastHit     = hit.transform.GetComponent <LaserPonterReciever>(); // TODO: Is there a less expensive method

            if (!oldLastHit)
            {
                oldLastHit = lastHit;
            }
            else if (oldLastHit != lastHit)
            {
                RayChanged();
            }

            if (!lastHit)
            {
                RayExit();
                return(endPosition);
            }

            if (IsClicking())
            {
                lastHit.Click(pointerHand);
                wasClicked = true;
            }
            else if (!materialUpdated)
            {
                lastHit.HitByRay();
                materialUpdated = true;
            }
        }
        else
        {
            endPosition = DefaultEnd(defaultLength);
            RayExit();
        }

        return(endPosition);
    }
Ejemplo n.º 9
0
    //if nothing has been set sset it as sendable object. If it is null and there us something there set it as sendable
    private void OnTriggerStay(Collider other)
    {
        if (entityCount == 0)
        {
            if (!other.CompareTag(AppData.chemicalTag) && !other.CompareTag(AppData.ignoreTag) && !other.CompareTag(AppData.elementTag))
            {
                GameObject          obj = other.gameObject;
                LaserPonterReciever lpr = obj.GetComponent <LaserPonterReciever>();

                if (lpr)
                {
                    lpr.rigidbody.useGravity  = false;
                    lpr.rigidbody.isKinematic = true;
                }

                objectInZone = obj.gameObject;
            }
            else if (other.CompareTag(AppData.elementTag))
            {
                GameObject obj = other.gameObject;

                if (!obj.GetComponent <ElementEffect>().IsReleased)
                {
                    return;
                }

                LaserPonterReciever lpr = obj.GetComponent <LaserPonterReciever>();

                if (lpr)
                {
                    lpr.rigidbody.useGravity  = false;
                    lpr.rigidbody.isKinematic = true;
                }

                objectInZone = obj.gameObject;
            }
        }
        else if (entityCount == 1 && objectInZone == null)
        {
            if (!other.CompareTag(AppData.chemicalTag) && !other.CompareTag(AppData.ignoreTag) && !other.CompareTag(AppData.elementTag))
            {
                GameObject          obj = other.gameObject;
                LaserPonterReciever lpr = obj.GetComponent <LaserPonterReciever>();

                if (lpr)
                {
                    lpr.rigidbody.useGravity  = false;
                    lpr.rigidbody.isKinematic = true;
                }

                objectInZone = obj.gameObject;
            }
            else if (other.CompareTag(AppData.elementTag))
            {
                GameObject obj = other.gameObject;

                if (!obj.GetComponent <ElementEffect>().IsReleased)
                {
                    return;
                }

                LaserPonterReciever lpr = obj.GetComponent <LaserPonterReciever>();

                if (lpr)
                {
                    lpr.rigidbody.useGravity  = false;
                    lpr.rigidbody.isKinematic = true;
                }

                objectInZone = obj.gameObject;
            }
        }
    }