void Play()
    {
        float m     = (path.nodes[currentSeg + 1].position - path.nodes[currentSeg].position).magnitude;
        float speed = (Time.deltaTime * 1 / m) * Speed;

        transition += speed;
        if (transition > 1)
        {
            transition = 0;
            currentSeg++;
            if (currentSeg == path.nodes.Length - 1)
            {
                Completed = true;
                return;
            }
        }
        else if (transition < 0)
        {
            transition = 1;
            currentSeg++;
        }

        transform.position = path.posOnRail(currentSeg, transition, mode);
        transform.rotation = path.Orientation(currentSeg, transition);
    }
示例#2
0
    private void Play()
    {
        float m = (rail.nodes [currentSeg + 1].position - rail.nodes [currentSeg].position).magnitude;
        float s = (Time.deltaTime * 1 / m) * moveSpeed;


        transition += s;
        if (transition > 1)
        {
            transition = 0;
            currentSeg++;
            if (currentSeg == rail.nodes.Length - 1)
            {
                if (loop)
                {
                    currentSeg = 0;
                }
                else
                {
                    isCompleted = true;
                    return;
                }
            }
        }
        else if (transition < 0)
        {
            transition = 1;
            currentSeg--;
        }

        transform.position = rail.PositionOnRail(currentSeg, transition, mode, rail.path);
        if (!VRMode)
        {
            transform.rotation = rail.Orientation(currentSeg, transition);
        }
    }
示例#3
0
    void FollowTrack()
    {
        transition += Time.deltaTime * 1 / 2.5f;

        if (transition > 1)
        {
            transition = 0;
            currentSeg++;
        }
        else if (transition < 0)
        {
            transition = 1;
            currentSeg++;
        }

        transform.position = rail.LinearPosition(currentSeg, transition);
        transform.rotation = rail.Orientation(currentSeg, transition);
    }
示例#4
0
    private void Play()
    {
        transition += Time.deltaTime * 1 / 2.5f;
        if (transition > 1)
        {
            transition = 0;
            currentSeg++;
        }

        if (currentSeg + 1 == rail.Length)
        {
            isCompleted = true;
        }
        else
        {
            transform.position = rail.PositionOnRail(currentSeg, transition, playMode);
            transform.rotation = rail.Orientation(currentSeg, transition);
        }
    }
示例#5
0
    private void Play()
    {
        if (setSpeed)
        {
            transition += Time.fixedDeltaTime * speed;
        }
        else
        {
            if (useEnt == true)
            {
                velocity = gameObject.GetComponent <Entity>().vel;
            }

            transition += Time.fixedDeltaTime * velocity.magnitude;
        }
        if (transition > 1)
        {
            transition = 0;
            current++;
        }
        else if (transition < 0)
        {
            transition = 1;
            current--;
        }
        if (current >= rail.nodes.Length - 1)
        {
            isComplete = true;
        }
        transform.position = rail.LinearPosition(current, transition);
        transform.rotation = rail.Orientation(current, transition);
        Vector3 rot = transform.rotation.eulerAngles;

        //use this to use rail like a water slide
        //transform.rotation = Quaternion.Euler(0, 0, rot.y);
        //Use this for rail grinding
        transform.rotation = Quaternion.Euler(0, 0, rot.x);
        //???
        //transform.rotation = Quaternion.Euler(0, 0, rot.z);
    }
示例#6
0
文件: RailMover.cs 项目: radmars/ld40
    private void Play(bool forward = true)
    {
        //calculate speed and stuff
        var   temp = rail.nodes.Length;
        float m    = (rail.nodes[currentSeg + 1].position - rail.nodes[currentSeg].position).magnitude;
        float s    = (Time.deltaTime * 1 / m) * speed;

        transition += (forward) ? s : -s;
        //check transition
        if (transition > 1)
        {
            transition = 0;
            currentSeg++;
            //if we reached the end
            if (currentSeg == rail.nodes.Length - 1)
            {
                finishedRoute = true;
                isStopped     = true;
                return;
            }
        }
        else if (transition < 0)
        {
            transition = 1;
            currentSeg--;

            if (currentSeg == -1)
            {
                isStopped = true;
                return;
            }
        }

        transform.position = rail.PositionOnRail(currentSeg, transition, mode, grounded);
        transform.rotation = rail.Orientation(currentSeg, transition);
    }
示例#7
0
    private void Play(bool forward = true)
    {
        float m = (rail.nodes[currentSeg + 1].position - rail.nodes[currentSeg].position).magnitude;
        float s = (Time.deltaTime * 1 / m) * speed;

        transition += (forward) ? s : -s;

        if (transition > 1)
        {
            transition = 0;
            currentSeg++;
            if (currentSeg == rail.nodes.Length - 1)
            {
                if (isLooping)
                {
                    if (pingPong)
                    {
                        transition = 1;
                        currentSeg = rail.nodes.Length - 2;
                        isReversed = !isReversed;
                    }
                    else
                    {
                        currentSeg = 0;
                    }
                }
                else
                {
                    isCompleted = true;
                    return;
                }
            }
        }
        else if (transition < 0)
        {
            transition = 1;
            currentSeg--;
            if (currentSeg == -1)
            {
                if (isLooping)
                {
                    if (pingPong)
                    {
                        transition = 0;
                        currentSeg = 0;
                        isReversed = !isReversed;
                    }
                    else
                    {
                        currentSeg = rail.nodes.Length - 2;
                    }
                }
                else
                {
                    isCompleted = true;
                    return;
                }
            }
        }

        transform.position = rail.PositionOnRail(currentSeg, transition, mode);
        transform.rotation = rail.Orientation(currentSeg, transition);
    }
    private void Play(bool forward = true)
    {
        float m = (rail.nodes[currentIndex + 1].position - rail.nodes[currentIndex].position).magnitude;
        float s = (Time.deltaTime * 1 / m) * speed;

        dot += (forward) ? s : -s;
        if (dot > 1)
        {
            dot = 0.0f;
            currentIndex++;
            if (currentIndex == rail.nodes.Length - 1)
            {
                if (isLooping)
                {
                    if (pingPong)
                    {
                        dot          = 1;
                        currentIndex = rail.nodes.Length - 2;
                        isReversed   = !isReversed;
                    }
                    else
                    {
                        currentIndex = 0;
                    }
                }
                else
                {
                    isCompleted = true;
                    return;
                }
            }
        }
        else if (dot < 0)
        {
            dot = 1;
            currentIndex--;
            if (currentIndex == -1)
            {
                if (isLooping)
                {
                    if (pingPong)
                    {
                        dot          = 0;
                        currentIndex = 0;
                        isReversed   = !isReversed;
                    }
                    else
                    {
                        currentIndex = rail.nodes.Length - 2;
                    }
                }
                else
                {
                    isCompleted = true;
                    return;
                }
            }
        }

        transform.position = rail.PositionOnRail(currentIndex, dot, mode);
        transform.rotation = rail.Orientation(currentIndex, dot);
    }
示例#9
0
    private void Move()
    {
        if (Time.timeScale == 0)
        {
            return;
        }
        TransitionPoint tp = rail.nodes[currentNodeIndex].gameObject.GetComponent <TransitionPoint>();

        RailTrigger[] rts = tp.getRailTriggers();

        if (rts.Length > 0)
        {
            foreach (RailTrigger rt in rts)
            {
                if (!rt.activated)
                {
                    if (rt.onEnter)
                    {
                        rt.Activate();
                    }
                }
            }
        }

        // Does this TP have requirements before we can move?
        if (!tp.metRequirements())
        {
            return;                        // If we haven't met the requirements, do not move
        }
        if (Camera.main.GetComponent <CameraCollider>().EnemiesNearby())
        {
            lastEnemyTime = Time.time;
            return; // Don't do anything if enemies nearby
        }
        else
        {
            if ((Time.time - lastEnemyTime) < ENEMY_KILLED_DELAY)
            {
                return;
            }
        }

        int targetIndex = (tp.targetPoint != null) ? tp.targetPoint.gameObject.GetComponent <TransitionPoint>().index : currentNodeIndex + 1;

        if (targetIndex >= rail.nodes.Count)           // We are on the last node
        // We've reached the end
        {
            isCompleted = true;
            return;
        }

        Vector3    targetPosition = rail.nodes[targetIndex].position;
        Quaternion targetRotation = rail.nodes[targetIndex].rotation;

        // We have met all requirements, we can move
        // The magnitude of the next TP and the current one
        float mP = (targetPosition - rail.nodes[currentNodeIndex].position).magnitude;
        // The point on the segment that we are on, based on the speed of the TP
        float sP = (Time.deltaTime * 1 / mP) * tp.transitionSpeed;

        transitionPosition += sP;

        float mQ = Quaternion.Angle(targetRotation, rail.nodes[currentNodeIndex].rotation);
        float sQ = (Time.deltaTime * 1 / mQ) * (tp.transitionSpeed * 10);

        transitionQuaternion += sQ;

        if ((transitionPosition >= 1 && transitionQuaternion >= 1) || (transitionPosition == Mathf.Infinity && transitionQuaternion == Mathf.Infinity))   // If we are moving forwards and reached our destination
        {
            if (rts.Length > 0)
            {
                foreach (RailTrigger rt in rts)
                {
                    if (!rt.activated)
                    {
                        if (!rt.onEnter)
                        {
                            rt.Activate();
                        }
                    }
                }
            }
            transitionPosition   = 0; // set the point on the line back to the beginning
            transitionQuaternion = 0;
            if (tp.targetPoint == null)
            {
                currentNodeIndex++;                 // Just go to the next segment
            }
            else
            {
                currentNodeIndex = tp.targetPoint.gameObject.GetComponent <TransitionPoint>().index;
            }
            if (currentNodeIndex == rail.nodes.Count)   // If we are on the last node
            {
                if (tp.targetPoint == null)
                {
                    isCompleted = true;
                    return;
                }
                else
                {
                    currentNodeIndex = tp.targetPoint.gameObject.GetComponent <TransitionPoint>().index;
                }
            }
        }

        // Move us
        transform.position = rail.PositionOnRail(currentNodeIndex, targetIndex, transitionPosition, mode);
        transform.rotation = rail.Orientation(currentNodeIndex, targetIndex, transitionQuaternion);
    }