コード例 #1
0
        void Update()
        {
            if (ungrabbableTimeElapsed < UNGRABBABLE_TIME)
            {
                ungrabbableTimeElapsed += Time.deltaTime;
            }
            else if (!ungrabbablePeriodOver)
            {
                GetComponent <VRTK_InteractableObject>().isGrabbable = true;
                ungrabbablePeriodOver = true;
            }

            if (trackController)
            {
                if (controllerToTrack != null)
                {
                    Vector3 diff = controllerToTrack.position - sourceCord.GetPathPointAtIndex(closestCordPointIndex);
                    controllerDistance = diff.sqrMagnitude;

                    if (controllerDistance < ShowDistanceSquared && closestCordPointIndex >= ClosestBranchPointToEnd && closestCordPointIndex <= sourceCord.NumPoints - ClosestBranchPointToEnd)
                    {
                        if (!wasShowing)
                        {
                            ShowHandle();
                        }

                        MoveToTargetPoint();
                    }
                    else if (wasShowing)
                    {
                        HideHandle();
                    }
                }
            }
        }
コード例 #2
0
        private void Update()
        {
            if (currentPointIndex != targetPointIndex && cord != null)
            {
                int nextPointIndex = NextPointIndex();

                Vector3 toNextPoint = (cord.GetPathPointAtIndex(nextPointIndex) - cord.GetPathPointAtIndex(currentPointIndex)).normalized;

                Vector3 nextPos = transform.position + toNextPoint * Speed * Time.deltaTime;

                Vector3 nextDiff = cord.GetPathPointAtIndex(nextPointIndex) - nextPos;

                if (!nextPos.Equals(cord.GetPathPointAtIndex(nextPointIndex)))
                {
                    while (Vector3.Dot(toNextPoint, nextDiff) < 0)
                    {
                        Vector3 nextMove = Vector3.zero;

                        currentPointIndex = nextPointIndex;
                        nextPointIndex    = NextPointIndex();

                        if (currentPointIndex == targetPointIndex)
                        {
                            nextPos = cord.GetPathPointAtIndex(targetPointIndex);
                            break;
                        }
                        else
                        {
                            nextMove = (cord.GetPathPointAtIndex(nextPointIndex) - cord.GetPathPointAtIndex(currentPointIndex)).normalized;
                            nextPos  = cord.GetPathPointAtIndex(currentPointIndex) + nextMove * nextDiff.magnitude;
                        }

                        nextDiff = cord.GetPathPointAtIndex(nextPointIndex) - nextPos;
                        OnNextPointReached(nextMove);
                    }
                }

                transform.position = nextPos;
            }
            else
            {
                transform.position = Vector3.Lerp(transform.position, cord.GetPathPointAtIndex(targetPointIndex), Time.deltaTime * SNAP_TO_TARGET_SPEED);
            }
        }