Ejemplo n.º 1
0
    public void UpdateATL(CurvySpline spline)
    {
        t = spline.GetNearestPointTF(transform.position);
        Vector3 splineAtT = spline.Interpolate(t);

        if (transform.position.y < splineAtT.y)
        {
            lastPos = splineAtT;
            Camera.main.GetComponent <CameraController_three> ().falling = true;
            //SceneManager.LoadScene ("three");
            StartCoroutine(Fall(5.0f, spline));                 //pass in length of fall
        }
        else
        {
            Camera.main.GetComponent <CameraController_three> ().falling = false;
        }

        if (!m_Jump)
        {
            m_Jump = Input.GetButtonDown("Jump");
        }

        //disabling jump
        m_Jump = false;
    }
        void FixedUpdate()
        {
            if (Spline)
            {
                var v = Input.GetAxis("Vertical") * VSpeed;
                var h = Input.GetAxis("Horizontal") * HSpeed;

                Vector3 p;
                // get nearest TF and point on spline
                mTF = Spline.GetNearestPointTF(transform.localPosition, out p);
                // apply forward thrust along spline direction (tangent)
                if (v != 0)
                {
                    mRigidBody.AddForce(Spline.GetTangentFast(mTF) * v, ForceMode.Force);
                }
                // apply side thrust to left/right from the spline's "forward" vector
                if (h != 0)
                {
                    Vector3 offset = Spline.GetExtrusionPointFast(mTF, 1, 90);
                    Vector3 hdir   = p - offset;
                    mRigidBody.AddForce(hdir * h, ForceMode.Force);
                }
                if (Input.GetKeyDown(KeyCode.Space))
                {
                    mRigidBody.AddForce(Vector3.up * JumpForce, ForceMode.Impulse);
                }

                // continously drag toward the spline to add some magic gravity
                mRigidBody.AddForce((Spline.Interpolate(mTF) - transform.localPosition) * CenterDrag, ForceMode.VelocityChange);
            }
        }
Ejemplo n.º 3
0
    IEnumerator NavigationLine(float waitTime)
    {
        while (true)
        {
            yield return(new WaitForSeconds(waitTime));

            CurvySpline curvySpline = pathEnhanced.GetComponent <CurvySpline>();
            segmentsToSearch.Add(curSegment);
            segmentsToSearch.Add(curvySpline[curSegment.SegmentIndex + 1].GetComponent <CurvySplineSegment>());
            segmentsToSearch.Add(curvySpline[curSegment.SegmentIndex - 1].GetComponent <CurvySplineSegment>());

            //float carTf = curvySpline.GetNearestPointTFExt(transform.position, segmentsToSearch.ToArray());
            float carTf = curvySpline.GetNearestPointTF(transform.position);

            Lane lane = MonitorLane(curvySpline.GetTangentFast(carTf));
            if (lane == Lane.RIGHT)
            {
                linesUtilsAlt.DrawLine(gameObject, curvySpline, carTf);
            }
            else
            {
                linesUtilsAlt.LineRend.positionCount = 0; //delete the LineRenderer
            }
            curSegment = curvySpline.TFToSegment(carTf);
            segmentsToSearch.Clear();
        }
    }
Ejemplo n.º 4
0
    IEnumerator InitNavigationLine()
    {
        curvySpline = pathEnhanced.GetComponent <CurvySpline>();
        while (!curvySpline.IsInitialized)
        {
            yield return(null);
        }
        float carTf = curvySpline.GetNearestPointTF(transform.position);

        curSegment = curvySpline.TFToSegment(carTf);
    }
Ejemplo n.º 5
0
    // Update is called once per frame
    public void UpdateATL(SplineLord_one splineLord_one, BookController bookController)
    {
        //print (Input.mouseScrollDelta.y);

        speed = -Input.mouseScrollDelta.y * _sensitivity;
        transform.position -= transform.up * _offset.y;
        _jumpTimer          = Mathf.Clamp01(_jumpTimer - Time.deltaTime);

        if (Input.GetKeyDown(KeyCode.Space) && _jumpTimer <= 0.0f)           //getkeydown only true first frame down, getkeyup true first frame released, getkey is true if down and false if up
        {
            _jumpTimer = 1.0f;
        }
        _offset = new Vector3(0.0f, Mathf.Sin(AxKEasing.EaseOutQuad(0.0f, 1.0f, 1.0f - _jumpTimer) * Mathf.PI), 0.0f);

        CurvySpline curSpline = splineLord_one.GetSpline();

        //this way gets nearest point on spline to current position
        t  = curSpline.GetNearestPointTF(transform.position);
        t += (speed / curSpline.Length) * Time.deltaTime * 5.0f;
        transform.position = curSpline.Interpolate(t);

        //Vector3 sForward = curSpline.GetTangentToSpline( t );
        //Vector3 sNormal = curSpline.GetOrientationOnSpline (t);
        //Quaternion lookRotation = Quaternion.LookRotation (sForward, sNormal);

        transform.rotation = Quaternion.Slerp(transform.rotation, curSpline.GetOrientationFast(t), Time.deltaTime * 5.0f);

        transform.position += transform.up * _offset.y;         //places player over spline

        int     indexOffset = 4;
        Vector3 v1          = curSpline.ControlPoints [0 + indexOffset].transform.position - curSpline.ControlPoints [1 + indexOffset].transform.position;
        Vector3 v2          = transform.position - curSpline.ControlPoints [1 + indexOffset].transform.position;
        float   dot         = Vector3.Dot(v1, v2);

        //print ( (Time.timeSinceLevelLoad % 2.0f).ToString( "F7" ) + "  " + ( Time.timeSinceLevelLoad ).ToString( "F5" ) + "  " + ( Time.timeSinceLevelLoad / 2.0f ).ToString( "F6") );
        if (Time.timeSinceLevelLoad % 2.0f <= 0.1f)          // dot < -.2)
        {
            //splineLord.CreateControlPoint ();
        }

        if (t > .5)
        {
            //SplineLord.GenerateSpline(curSpline);
        }

        /*
         * if (t > .5)
         * {
         * splineLord.RegisterSpline() (next: get end pt from data stream)
         * delete last spline
         * }
         */
    }
Ejemplo n.º 6
0
    // Update is called once per frame
    public void UpdateATL(ThirdPersonUserControl player, CurvySpline spline)
    {
        if (!init && spline.IsInitialized)
        {
            init = true;
            t    = spline.GetNearestPointTF(player.transform.position);
        }

        if (!init)
        {
            return;
        }

        t = spline.GetNearestPointTF(player.transform.position);
        float indexf = t / (1f / _childMeshes.Count);         //assuming this rounds down to int

        indexf = indexf - t % (1f / _childMeshes.Count);
        int index = (int)indexf;

        // t goes from 0 to 1. count of meshes goes from 0 to count.
        // 1 / count is the approximate "t" length of each segment
        // t / ( 1/count) is the number of segments that fit into t
        // enable a range of ints around t/(1/count)

        for (int i = 0; i < _childMeshes.Count; i++)
        {
            if (i > index - 3 && i < index + 3)
            {
                _childMeshes [i].GetComponent <ConcaveCollider> ().enabled = true;
                //_childMeshes [i].GetComponent<MeshCollider> ().enabled = false;
            }
            else
            {
                _childMeshes [i].GetComponent <ConcaveCollider> ().enabled = false;
                //_childMeshes [i].GetComponent<MeshCollider> ().enabled = true;
            }
        }
    }
Ejemplo n.º 7
0
    IEnumerator LaneKeeping(float waitTime)
    {
        while (true)
        {
            yield return(new WaitForSeconds(waitTime));

            RaycastHit  hit;
            CurvySpline curvySpline             = null;
            CurvySpline pathEnhancedCurvySpline = null;
            if (Physics.Raycast(rayCastPos.position, rayCastPos.TransformDirection(-Vector3.up), out hit, 10.0f, 1 << LayerMask.NameToLayer("Graphics")))
            {
                curvySpline             = hit.collider.gameObject.GetComponent <CurvySpline>();
                pathEnhancedCurvySpline = pathEnhanced.GetComponent <CurvySpline>();
                if (curvySpline.IsInitialized && pathEnhancedCurvySpline.IsInitialized)
                {
                    //Debug.Log("meshcollider found is: " + hit.collider);
                    float   carTf           = curvySpline.GetNearestPointTF(transform.position); //determine the nearest t of the car with respect to the centerLine
                    Vector3 centerLinePoint = curvySpline.Interpolate(carTf);
                    float   dist            = Vector3.Distance(transform.position, centerLinePoint);
                    Lane    lane            = MonitorLane(centerLinePoint); //this is to understand if I am partially in the oncoming lane

                    if (dist < 2.0f && lane == Lane.RIGHT)                  //if dist2 < 2.7f I am in the right lane
                    {
                        linesUtilsAlt.CenterLineColor = linesUtilsAlt.ChangeMatByDistance(dist / 2.0f);
                        SetDashBoardColor(dist, 2.0f);
                    }

                    else if (dist >= 2.0f && lane == Lane.RIGHT)
                    {
                        linesUtilsAlt.CenterLineColor = new Color32(0x00, 0xFF, 0x00, 0x00);
                        laneState = LaneState.GREEN;
                    }

                    else if (lane == Lane.OPPOSITE) // this is to draw the redLine only when the PlayerCar is moving to the left, if it is moving to the right the line doesn't have to be red!
                    {
                        linesUtilsAlt.CenterLineColor = new Color32(0xFF, 0x00, 0x00, 0xFF);
                        laneState = LaneState.RED;
                    }

                    linesUtilsAlt.DrawCenterLine(gameObject, carTf, curvySpline, ResourceHandler.instance.sprites[36].texture);
                }
            }
            else
            {
                laneState = LaneState.GREEN;
            }
        }
    }
Ejemplo n.º 8
0
 // Update is called once per frame
 void Update()
 {
     if (Spline && Spline.IsInitialized && Lookup)
     {
         // convert Lookup position to Spline's local space
         var lookupPos = Spline.transform.InverseTransformPoint(Lookup.position);
         // get the nearest point's TF on spline
         Timer.Start();
         float nearestTF = Spline.GetNearestPointTF(lookupPos);
         Timer.Stop();
         // convert the spline pos back to world space and set
         transform.position  = Spline.transform.TransformPoint(Spline.Interpolate(nearestTF));
         StatisticsText.text =
             string.Format("Blue Curve Cache Points: {0} \nAverage Lookup (ms): {1:0.000}", Spline.CacheSize, Timer.AverageMS);
     }
 }
        void DoFindPoint()
        {
            if (!mSpline.IsInitialized || SourcePoint.IsNone)
            {
                return;
            }

            if (StoreTF.IsNone && StorePosition.IsNone && StoreUpVector.IsNone && StoreRotation.IsNone && StoreTangent.IsNone)
            {
                return;
            }

            Vector3 pos = (Space == Space.Self) ? SourcePoint.Value : mSpline.transform.InverseTransformPoint(SourcePoint.Value);

            float _tf = mSpline.GetNearestPointTF(pos);

            if (StoreTF.IsNone == false)
            {
                StoreTF.Value = _tf;
            }

            if (StorePosition.IsNone == false)
            {
                StorePosition.Value = (Space == Space.Self) ? mSpline.Interpolate(_tf) : mSpline.transform.TransformPoint(mSpline.Interpolate(_tf));
            }

            if (StoreTangent.IsNone == false)
            {
                StoreTangent.Value = (Space == Space.Self) ? mSpline.GetTangent(_tf) : mSpline.transform.TransformDirection(mSpline.GetTangent(_tf));
            }

            if (StoreUpVector.IsNone == false)
            {
                StoreUpVector.Value = (Space == Space.Self) ? mSpline.GetOrientationUpFast(_tf) : mSpline.transform.TransformDirection(mSpline.GetOrientationUpFast(_tf));
            }
            if (StoreRotation.IsNone == false)
            {
                if (Space == Space.Self)
                {
                    StoreRotation.Value = (StoreUpVector.IsNone) ? mSpline.GetOrientationFast(_tf) : Quaternion.LookRotation(mSpline.GetTangent(_tf), StoreUpVector.Value);
                }
                else
                {
                    StoreRotation.Value = Quaternion.LookRotation(mSpline.transform.TransformDirection(mSpline.GetTangent(_tf)), mSpline.transform.TransformDirection(mSpline.GetOrientationUpFast(_tf)));
                }
            }
        }
Ejemplo n.º 10
0
    IEnumerator LaneKeeping(float waitTime)
    {
        while (true)
        {
            yield return(new WaitForSeconds(waitTime));

            RaycastHit  hit;
            CurvySpline curvySpline             = null;
            CurvySpline pathEnhancedCurvySpline = null;
            if (Physics.Raycast(rayCastPos.position, rayCastPos.TransformDirection(-Vector3.up), out hit, 10.0f, 1 << LayerMask.NameToLayer("Graphics")))
            {
                curvySpline             = hit.collider.gameObject.GetComponent <CurvySpline>();
                pathEnhancedCurvySpline = pathEnhanced.GetComponent <CurvySpline>();
                if (curvySpline.IsInitialized && pathEnhancedCurvySpline.IsInitialized)
                {
                    float carTf  = curvySpline.GetNearestPointTF(transform.position); //determine the nearest t of the car with respect to the centerLine
                    float carTf2 = pathEnhancedCurvySpline.GetNearestPointTF(transform.position);
                    float dist   = Vector3.Distance(transform.position, curvySpline.Interpolate(carTf));
                    Lane  lane   = MonitorLane(pathEnhancedCurvySpline.GetTangentFast(carTf2)); //this is to understand if I am partially in the oncoming lane
                    if (dist < 4.0f && lane == Lane.RIGHT)
                    {
                        linesUtilsAlt.CenterLineColor = linesUtilsAlt.ChangeMatByDistance(dist / 4.0f);
                        SetDashBoardColor(dist, 4.0f);
                    }

                    else if (dist >= 4.0f && lane == Lane.RIGHT)
                    {
                        linesUtilsAlt.CenterLineColor = new Color32(0x00, 0xFF, 0x00, 0x00);
                        laneState = LaneState.GREEN;
                    }

                    else if (lane == Lane.OPPOSITE)
                    {
                        linesUtilsAlt.CenterLineColor = new Color32(0xFF, 0x00, 0x00, 0xFF);
                        laneState = LaneState.RED;
                    }

                    linesUtilsAlt.DrawCenterLine(carTf, MonitorLane(curvySpline.GetTangentFast(carTf)), curvySpline, ResourceHandler.instance.sprites[33].texture);
                }
            }
            else
            {
                laneState = LaneState.GREEN;
            }
        }
    }
Ejemplo n.º 11
0
    public void UpdateATL(ThirdPersonUserControl player_three, Crosshair crosshair, CurvySpline spline)
    {
        _targetDelay -= Time.deltaTime;

        // aim through crosshair
        Quaternion targetDirection = Quaternion.LookRotation(crosshair.transform.forward);

        // passed the crosshair and delay
        if (_targetDelay < 0.5f)
        {
            if (_speed > 10.0f)
            {
                _speed -= Time.deltaTime;
            }

            if (Vector3.Distance(gameObject.transform.position, player_three.transform.position) < 5.0f)
            {
                onceAround = true;
            }

            // going around track
            if (!onceAround)
            {
                float t = spline.GetNearestPointTF(gameObject.transform.position);
                t *= .95f;
                Vector3 splineUp       = spline.GetRotatedUpFast(t, 0);
                Vector3 targetPosition = spline.Interpolate(t) + splineUp * 1.7f;

                targetDirection = Quaternion.LookRotation((targetPosition - transform.position).normalized);
            }
            // circling player - should be the gun
            else if (onceAround)
            {
                targetDirection = Quaternion.LookRotation(((player_three.transform.position + player_three.transform.up) - transform.position).normalized); //aim at heart
            }
        }

        transform.rotation = Quaternion.Slerp(transform.rotation, targetDirection, Time.deltaTime);
        Vector3 velocity = (transform.forward) * _speed;

        GetComponent <Rigidbody>().MovePosition(transform.position + velocity * Time.deltaTime);
    }
Ejemplo n.º 12
0
    public void UpdateATL(ThirdPersonUserControl player, CurvySpline spline)
    {
        if (!init && spline.IsInitialized)
        {
            init = true;
        }

        if (!init)
        {
            return;
        }

        //print("mouse x " + Input.GetAxis("Mouse X") + ", mouse y " + Input.GetAxis("Mouse Y"));
        offset += new Vector3(-Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y"), 0.0f);

        t = spline.GetNearestPointTF(player.transform.position);
        Vector3 splineUp = spline.GetRotatedUpFast(t, 0);
        //AxKDebugLines.AddLine (player.transform.position, player.transform.position + splineUp, Color.red, .001f);
        Vector3 splineForward = spline.GetTangent(t);
        Vector3 splineRight   = Vector3.Cross(splineUp, splineForward);

        Vector3 tempOffset = splineRight * offset.x + splineUp * offset.y;         //changed from Vector3.up

        float   targetPositionT = t - offsetCrosshair / spline.Length;
        Vector3 targetT         = spline.Interpolate(targetPositionT);
        Vector3 targetPosition  = targetT + tempOffset;

        transform.position = Vector3.Lerp(transform.position, targetPosition, Time.deltaTime * smooth * 3.0f);
        //transform.localRotation = Quaternion.Slerp( transform.localRotation, Quaternion.LookRotation (-splineForward.normalized), Time.deltaTime * smooth );

        //clamp the final position to this
        Vector3 pos = Camera.main.WorldToViewportPoint(transform.position);

        pos.x = Mathf.Clamp01(pos.x);
        pos.y = Mathf.Clamp01(pos.y);
        transform.position = Camera.main.ViewportToWorldPoint(pos);

        //transform.position = targetPosition;
        transform.localRotation = Camera.main.transform.localRotation;

        if (fire)         //fire is only true for one frame
        {
            _small.gameObject.GetComponent <Renderer> ().material  = fireS;
            _medium.gameObject.GetComponent <Renderer> ().material = fireM;
            _large.gameObject.GetComponent <Renderer> ().material  = fireL;

            //print ("in fire, mat name = " + _medium.gameObject.GetComponent<Renderer> ().material.name);
            StartCoroutine(Delay(.5f));
        }
        else if (aim && !fire)
        {
            _small.localRotation  = Quaternion.Euler(transform.localRotation.y, transform.localRotation.x, tempOffset.x * 300.0f);
            _medium.localRotation = Quaternion.Euler(transform.localRotation.y, transform.localRotation.x, tempOffset.y * 300.0f);             //y = Time.time; // * 180.0f; // Quaternion.AngleAxis (Time.time * 180.0f , transform.forward);

            _small.gameObject.GetComponent <Renderer> ().material  = aimS;
            _medium.gameObject.GetComponent <Renderer> ().material = aimM;
            _large.gameObject.GetComponent <Renderer> ().material  = aimL;
            //print ("in aim, mat name = " + _medium.gameObject.GetComponent<Renderer> ().material.name);
        }
        else
        {
            //ease back. only call on return
            _small.localRotation  = Quaternion.Slerp(_small.localRotation, Quaternion.Euler(Vector3.zero), Time.deltaTime);
            _medium.localRotation = Quaternion.Slerp(_medium.localRotation, Quaternion.Euler(Vector3.zero), Time.deltaTime);

            _small.gameObject.GetComponent <Renderer> ().material  = readyS;
            _medium.gameObject.GetComponent <Renderer> ().material = readyM;
            _large.gameObject.GetComponent <Renderer> ().material  = readyL;
            //print ("in ready, mat name = " + _medium.gameObject.GetComponent<Renderer> ().material.name);
        }
    }
Ejemplo n.º 13
0
        protected override void Update()
        {
            // INPUT

            // Jump?
            if (Input.GetButtonDown("Fire1") && mMode == GuideMode.Guided)
            {
                StartCoroutine(Jump());
            }
            // If allowed to switch and player wants to, initiate switching
            if (mPossibleSwitchTarget != null && mSwitchInProgress == 0)
            {
                float xAxis = Input.GetAxisRaw("Horizontal");
                if (mPossibleSwitchTarget.Options == "Right" && xAxis > 0)
                {
                    Switch(1);
                }
                else if (mPossibleSwitchTarget.Options == "Left" && xAxis < 0)
                {
                    Switch(-1);
                }
            }
            // else check if we need to finalize the switch process
            else if (mSwitchInProgress != 0 && !IsSwitching)
            {
                mSwitchInProgress = 0;
                OnCPReached(new CurvySplineMoveEventArgs(this, Spline, Spline.TFToSegment(RelativePosition), 0, 0, 0));
            }

            // MOVEMENT

            // If not falling
            if (mMode != GuideMode.FreeFall)
            {
                // Let the controller advance
                base.Update();

                // if we're jumping, translate back to the wanted height above track
                if (mHeightOverGround > 0 && mMode == GuideMode.Jumping)
                {
                    transform.Translate(new Vector3(0, mHeightOverGround, 0), Space.Self);
                }
            }
            else
            { // handling falling
                mDownSpeed += Gravity * Time.deltaTime;
                // advance using last known velocity vector
                transform.Translate(new Vector3(0, -mDownSpeed, Speed * Time.deltaTime));
                // check distance to falling target and reenter "guided" mode when near
                // NOTE: to support falling to multiple targets one would skip this method and use a trigger instead that collides with track geometry and reenters "guided" mode then
                var     posInTargetSpace = mFreeFallTarget.transform.InverseTransformPoint(transform.position);
                Vector3 nearestPoint;
                var     nearestPointTF = mFreeFallTarget.GetNearestPointTF(posInTargetSpace, out nearestPoint);
                if ((nearestPoint - posInTargetSpace).magnitude <= 2f)
                {
                    Spline           = mFreeFallTarget;
                    RelativePosition = nearestPointTF;
                    mMode            = GuideMode.Guided;
                    mDownSpeed       = 0;
                    mFreeFallTarget  = null;
                }
            }
        }
Ejemplo n.º 14
0
    public void UpdateATL(ThirdPersonUserControl player, CurvySpline spline)
    {
        if (!init && spline.IsInitialized)
        {
            init = true;
        }

        if (!init)
        {
            return;
        }

        if (!Camera.main.GetComponent <CameraController_three> ().CUbool&& !wasdDone)
        {
            //player.GetComponentInChildren<MakeMesh> (true).enabled = true;
            MakeTextGO("TO MOVE HOLD DOWN WASD");              //0-17 before "W"
            wasdDone = true;
        }
        if (Input.GetKeyDown(KeyCode.W) && !wPressed)
        {
            SwapCharGO(' ', 14);             // replace W with a space
            wPressed = true;
        }
        if (Input.GetKeyDown(KeyCode.A) && !aPressed)
        {
            SwapCharGO(' ', 15);
            aPressed = true;
        }
        if (Input.GetKeyDown(KeyCode.S) && !sPressed)
        {
            SwapCharGO(' ', 16);
            sPressed = true;
        }
        if (Input.GetKeyDown(KeyCode.D) && !dPressed)
        {
            SwapCharGO(' ', 17);
            dPressed = true;
        }

        // conditionals for which words to show
        if (wPressed && sPressed && aPressed && dPressed && !wasdCleared)
        {
            Clear();
            wasdCleared = true;
        }
        if (player.GetComponent <ThirdPersonCharacter> ().SeenGun() && !qDone && wasdCleared)         //must evade intro wide with gun in view
        {
            MakeTextGO("PRESS Q TO PICKUP");
            qDone = true;
        }
        if (player.GetComponent <ThirdPersonCharacter> ().m_pickup == true && !mouseAimDone)
        {
            MakeTextGO("PRESS LEFT MOUSE DOWN TO AIM");
            mouseAimDone = true;
        }
        if (player.GetComponent <ThirdPersonCharacter> ().m_doneAim == true && !mouseFireDone)
        {
            MakeTextGO("RELEASE LEFT MOUSE TO FIRE");
            mouseFireDone = true;
            //StartCoroutine (Fade (4.0f)); //do on fireFlag below
        }
        if (player.GetComponent <ThirdPersonCharacter> ().m_fireFlag == true & !fireCleared)
        {
            Clear();
            fireCleared = true;
        }

        float t = spline.GetNearestPointTF(player.transform.position);

        //AxKDebugLines.AddSphere (spline.Interpolate (maxT), 0.3f, Color.green);
        //AxKDebugLines.AddSphere (spline.Interpolate (minT), 0.3f, Color.magenta);

        Vector3 splineUp      = spline.GetRotatedUpFast(t, 0);
        Vector3 splineForward = spline.GetTangent(t);
        Vector3 splineRight   = Vector3.Cross(splineUp, splineForward);

        //Vector3 rise = splineRight * offset.x + splineUp * offset.y + splineForward * offset.z;

        Vector3 lookPosition = Camera.main.transform.position;
        //Vector3 targetPosition = player.transform.position + player.transform.right * 0.8f * textLength / 4 + player.transform.up * 4.0f - player.transform.forward * 3.0f;
        Vector3 targetPosition = spline.Interpolate(t) + splineRight * 0.8f * textLength / 3 + splineUp * 4.0f - splineForward * 3.0f;

        //AxKDebugLines.AddSphere (lookPosition, .1f, Color.red);
        //AxKDebugLines.AddSphere (targetPosition, .1f, Color.blue);

        transform.position = Vector3.Lerp(transform.position, targetPosition, Time.deltaTime * smooth);
        transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation((lookPosition - transform.position).normalized), Time.deltaTime * smooth);
    }
Ejemplo n.º 15
0
    public void UpdateATL(ThirdPersonUserControl player, CurvySpline spline)
    {
        if (!init && spline.IsInitialized)
        {
            init = true;
            t    = spline.GetNearestPointTF(player.transform.position);

            minT = t - (buffer / spline.Length) / 2.0f;
            maxT = t + (buffer / spline.Length) / 2.0f;
        }

        if (!init)
        {
            return;
        }

        //print ("spline name = " + spline.name);

        float playerT = spline.GetNearestPointTF(player.transform.position);

        //print ("playerT = " + playerT);
        //AxKDebugLines.AddSphere (player.transform.position, 0.3f, Color.green);
        //AxKDebugLines.AddSphere (spline.Interpolate (player.transform.position), 0.3f, Color.magenta);
        //AxKDebugLines.AddSphere (spline.Interpolate (playerT), 0.3f, Color.blue);

        if (playerT > maxT)
        {
            maxT = playerT;
            minT = maxT - (buffer / spline.Length);
            t    = playerT;
        }
        else if (playerT < minT)
        {
            minT = playerT;
            maxT = minT + (buffer / spline.Length);
            t    = playerT;
        }

        //AxKDebugLines.AddSphere (spline.Interpolate (maxT), 0.3f, Color.green);
        //AxKDebugLines.AddSphere (spline.Interpolate (minT), 0.3f, Color.magenta);

        splineUp      = spline.GetRotatedUpFast(t, 0);
        splineForward = spline.GetTangent(t);
        splineRight   = Vector3.Cross(splineUp, splineForward);
        //print ("offset = " + offset);

        Vector3 rise = splineUp * offset.y + splineForward * offset.z + splineRight * offset.x * Mathf.Sin(Mathf.Sqrt(Time.time));

        float   targetPositionT = t + offsetCam / spline.Length;
        Vector3 targetPosition  = spline.Interpolate(targetPositionT) + rise;

        float   lookPositionT = t - offsetLook / spline.Length;
        Vector3 lookPosition  = spline.Interpolate(lookPositionT);

        targetPosition = ((targetPosition * 4f) + player.transform.position) / 5f;

        if (CUbool)
        {
            lookPosition   = player.transform.position + player.transform.up * 2.55f;
            targetPosition = lookPosition + player.transform.forward * .4f;
            //print ("in bool");
        }
        else if (falling)
        {
            lookPosition   = player.transform.position;
            targetPosition = transform.position;
        }

        transform.position = Vector3.Lerp(transform.position, targetPosition, Time.deltaTime * smooth);
        transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation((lookPosition - transform.position).normalized), Time.deltaTime * smooth);
    }