Esempio n. 1
0
        void Start()
        {
            playMode    = true;
            storedSpeed = moveSpeed;
            moverObject = this.gameObject;

            if (newStartNode != null)
            {
                startNodeInt = moverNodes.IndexOf(newStartNode) + 1;
            }

            if (!reverseDirection) // if standard direction of movement
            {
                destinationNode = moverNodes[startNodeInt];
            }
            else if (reverseDirection) // if reverse direction
            {
                destinationNode = moverNodes[moverNodes.Count - startNodeInt];
            }

            if (startNodeInt > 1)
            {
                moverObject.transform.position = moverNodes[startNodeInt - 1].transform.position;
            }

            wait = false;
        }
Esempio n. 2
0
 public void RefreshNodeList()
 {
     moverNodes.Clear();
     {
         foreach (Transform t in nodeContainer.transform)
         {
             QS_MoverNode node = t.GetComponent <QS_MoverNode>();
             if (!moverNodes.Contains(node))
             {
                 moverNodes.Add(node);
             }
         }
     }
 }
Esempio n. 3
0
        void RotatePlatform() // Called from Fixed Update
        {
            // Standard rotation
            Quaternion newRotation;
            Quaternion lookAtRotation;

            if (distanceToNode > 0.1f)
            {
                newRotation = Quaternion.LookRotation(destinationNode.transform.position - transform.position);
            }

            else
            {
                newRotation = transform.rotation;
            }


            if (previousNode == null)
            {
                previousNode = moverNodes[0];
            }

            if (rotationType == rotationEnum.byTurnSpeed)
            {
                lookAtRotation = Quaternion.Lerp(transform.rotation, newRotation, RotationPercent());
            }
            else
            {
                lookAtRotation = Quaternion.Lerp(prevFacingRot, newRotation, RotationPercent());
            }

            // Lock axis to stay level
            if (stayLevel)
            {
                // Rotate the platform on Y only
                // Use our own unchanged x and y rotation to stay level,
                // And use the slerped y to rotate around that axis, we also take the new W to prevent gimble shenanigans.
                transform.rotation = new Quaternion(transform.rotation.x, lookAtRotation.y, transform.rotation.z, lookAtRotation.w);
            }
            else
            {
                //transform.rotation = Quaternion.Slerp (transform.rotation, newRotation, Time.fixedDeltaTime * turnSpeed);
                transform.rotation = lookAtRotation;
            }
        }
Esempio n. 4
0
 void GetPrevNode() // Called at end of Next Node
 {
     if (reverseDirection)
     {
         prevNodeInt = moverNodes.IndexOf(destinationNode) + 1;
         if (prevNodeInt > moverNodes.Count - 1 && loop)
         {
             prevNodeInt = 0;
         }
     }
     else if (!reverseDirection)
     {
         prevNodeInt = moverNodes.IndexOf(destinationNode) - 1;
         if (prevNodeInt < 0 && loop)
         {
             prevNodeInt = moverNodes.Count - 1;
         }
     }
     previousNode = moverNodes[prevNodeInt];
 }
Esempio n. 5
0
        void NextNode() // Called when platform reaches its destination node
        {
            if (!wait && isAtDest && !newDestSet)
            {
                int currentNode = moverNodes.IndexOf(destinationNode);
                prevFacingRot = transform.rotation;
                //turnPercent = 0;

                if (!loop)
                {
                    if (autoReturn)
                    {
                        if (currentNode + 1 == moverNodes.Count)
                        {
                            reverseDirection = true;
                        }
                        else if (currentNode - 1 == -1)
                        {
                            reverseDirection = false;
                        }
                    }
                    if (!reverseDirection && currentNode < moverNodes.Count - 1) // Standard direction && if node is not the last
                    {
                        destinationNode = moverNodes[currentNode + 1];
                    }
                    else if (reverseDirection && currentNode > 0) // Reverse direction && current node is not the first
                    {
                        destinationNode = moverNodes[currentNode - 1];
                    }
                }
                else if (loop)
                {
                    if (!reverseDirection)
                    {
                        //Ternary Operator
                        // thisVariable = depending if this statement is true ? will equal this if true : or this if false
                        destinationNode = currentNode + 1 == moverNodes.Count ? moverNodes[0] : moverNodes[currentNode + 1];
                    }
                    else if (reverseDirection)
                    {
                        destinationNode = currentNode - 1 == -1 ? moverNodes[moverNodes.Count - 1] : moverNodes[currentNode - 1];
                    }
                }

                // Apply speed from destination node
                if (destinationNode != null && destinationNode.overrideSpeed)
                {
                    moveSpeed = destinationNode.moveSpeed;
                }
                else
                {
                    if (moveSpeed != storedSpeed)
                    {
                        storedSpeed = moveSpeed;
                    }
                    else
                    {
                        moveSpeed = storedSpeed;
                    }

                    smoothSpeed = storedSpeed;
                }
                newDestSet = true;
            }
            GetPrevNode();
        }