コード例 #1
0
    private void WalkSpline()
    {
        if (t < 1f)
        {
            t += speed * Time.deltaTime;
        }
        else
        {
            t -= 1f;
            if (index < maxIndex)
            {
                index++;
            }
            else
            {
                index = splineResolution * 2;
                controlPoints.Dequeue();
                UpdateSpline();
            }
        }

        var     a   = splinePoints[index];
        var     b   = splinePoints[index + 1];
        Vector3 pos = Vector3.Lerp(a.position, b.position, t);
        Vector3 tan = Vector3.Lerp(a.tangent, b.tangent, t);

        pos               += GetCentroid(transform, obstacleDetectionRange);
        position           = Vector3.SmoothDamp(position, pos, ref posDampVelo, positionDampTime);
        tangent            = Vector3.SmoothDamp(tangent, tan, ref tanDampVelo, tangentDampTime);
        transform.position = position;
        transform.rotation = Quaternion.LookRotation(tangent);

        spline.DrawSpline(Color.white);
    }
コード例 #2
0
    void Update()
    {
        if (spline != null)
        {
            spline.Update(controlPoints);
            spline.Update(resolution);
            spline.DrawSpline(Color.white);

            if (drawNormal)
            {
                spline.DrawNormals(normalExtrusion, Color.red);
            }

            if (drawTangent)
            {
                spline.DrawTangents(tangentExtrusion, Color.cyan);
            }
        }
        else
        {
            spline = new CatmullRom(controlPoints, resolution);
        }


        if (globalTime <= 1)
        {
            globalTime += Time.deltaTime * UpdateProgress();
        }
        else
        {
            globalTime = .001f;
        }

        UpdatePosition(globalTime);
    }
コード例 #3
0
 void Update()
 {
     if (_catmull != null)
     {
         //_catmull.Update(_points);
         _catmull.Update(resolution, false);
         //Debug.Log( _catmull.GetPoints().Length );
         _catmull.DrawSpline(Color.white);
     }
 }
コード例 #4
0
    void Update()
    {
        if (spline != null)
        {
            spline.Update(controlPoints);
            spline.Update(resolution);
            spline.DrawSpline(Color.white);

            if (drawNormal)
            {
                spline.DrawNormals(normalExtrusion, Color.red);
            }

            if (drawTangent)
            {
                spline.DrawTangents(tangentExtrusion, Color.cyan);
            }
        }
        else
        {
            spline = new CatmullRom(controlPoints, resolution);
        }


        if (speed > 0)
        {
            Debug.Log(spline.GetPoints().Length);

            float distance = Vector3.Distance(spline.GetPoints()[currentWaypointID].position, transform.position);
            transform.position = Vector3.MoveTowards(transform.position, spline.GetPoints()[currentWaypointID].position, Time.deltaTime * speed);

            var rotation = Quaternion.LookRotation(spline.GetPoints()[currentWaypointID].position - transform.position);
            transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * rotationSpeed);

            if (distance <= reachDistance)
            {
                currentWaypointID++;
            }
        }

        if (currentWaypointID >= spline.GetPoints().Length)
        {
            currentWaypointID  = 0;
            transform.position = spline.GetPoints()[currentWaypointID].position;
            transform.rotation = Quaternion.LookRotation(spline.GetPoints()[currentWaypointID].position - transform.position);
        }
    }
コード例 #5
0
    void Update()
    {
        if (spline != null)
        {
            spline.Update(controlPoints);
            spline.Update(resolution);
            spline.DrawSpline(Color.white);

            if (drawNormal)
            {
                spline.DrawNormals(normalExtrusion, Color.red);
            }

            if (drawTangent)
            {
                spline.DrawTangents(tangentExtrusion, Color.cyan);
            }
        }
        else
        {
            spline = new CatmullRom(controlPoints, resolution);
        }



        if (progress <= 1)
        {
            progress += Time.deltaTime * UpdateProgress();
            //if (!trail.emitting) {
            //trail.Clear();
            //trail.emitting = true;
            //}
        }
        else
        {
            progress = .001f;
            //trail.emitting = false;
        }

        UpdatePosition(progress);
    }
コード例 #6
0
ファイル: Spline.cs プロジェクト: UnManuel/Cars
    void Update()
    {
        if (spline != null)
        {
            spline.Update(controlPoints);
            spline.Update(resolution, closedLoop);
            spline.DrawSpline(color);

            if (drawNormal)
            {
                spline.DrawNormals(normalExtrusion, Color.red);
            }

            if (drawTangent)
            {
                spline.DrawTangents(tangentExtrusion, Color.cyan);
            }
        }
        else
        {
            spline = new CatmullRom(controlPoints, resolution, closedLoop);
        }
    }