Example #1
0
        private void Update()
        {
            if (goingForward)
            {
                progress += Time.deltaTime / duration;
                if (progress > 1f)
                {
                    if (mode == WalkerMode.Once)
                    {
                        progress = 1f;
                    }
                    else if (mode == WalkerMode.Loop)
                    {
                        progress -= 1f;
                    }
                    else
                    {
                        progress     = 2f - progress;
                        goingForward = false;
                    }
                }
            }
            else
            {
                progress -= Time.deltaTime / duration;
                if (progress < 0)
                {
                    progress     = -progress;
                    goingForward = true;
                }
            }
            Vector3 position = path.GetPoint(progress);

            transform.localPosition = position;
            if (!backAndForthAlwaysForward)
            {
                if (lookForwards)
                {
                    transform.LookAt(position + path.GetDirection(progress));
                }
            }
            else
            {
                if (goingForward)
                {
                    transform.LookAt(position + path.GetDirection(progress));
                }
                else
                {
                    transform.LookAt(position - path.GetDirection(progress));
                }
            }
        }
        private void ShowDirections()
        {
            Handles.color = Color.green;
            Vector3 point = spline.GetPoint(0f);

            Handles.DrawLine(point, point + spline.GetDirection(0f) * directionScale);
            int steps = stepsPerCurve * spline.CurveCount;

            for (int i = 1; i <= steps; i++)
            {
                point = spline.GetPoint(i / (float)steps);
                Handles.DrawLine(point, point + spline.GetDirection(i / (float)steps) * directionScale);
            }
        }
Example #3
0
        Vector3[] WireVertices()
        {
            Vector3[] vertices = new Vector3[subDivisions * 4];

            for (int z = 0, i = 0; z < subDivisions; z++)
            {
                float   t         = Mathf.InverseLerp(0, subDivisions - 1, z);
                Vector3 center    = path.GetPoint(t);
                Vector3 direction = path.GetDirection(t);

                for (int x = 0; x < 4; x++, i++)
                {
                    float      angle    = Mathf.InverseLerp(0, 3, x) * 360;
                    Quaternion rotation = Quaternion.LookRotation(direction) * Quaternion.Euler(Vector3.forward * angle);
                    vertices[i] = (rotation * Vector3.up * (meshWidth) + transform.InverseTransformPoint(center));
                }
            }

            return(vertices);
        }
Example #4
0
        //public bool distanceBased = false;

        private void Awake()
        {
            path = GetComponent <BezierSpline>();

            if (frequency <= 0 || items.Length == 0 || path == null)
            {
                return;
            }

            int        index;
            float      step = 1f / ((float)frequency + 1f);
            Vector3    pos;
            Vector3    localDir;
            GameObject go;

            for (int i = 1; i <= frequency; i++)
            {
                index = Random.Range(0, items.Length - 1);
                pos   = path.GetPoint(i * step);

                if (localOffset)
                {
                    localDir = path.GetNormal(i * step);

                    go = Instantiate(items[index], pos + (heightOffset * localDir), items[index].transform.rotation, transform);
                }
                else
                {
                    go = Instantiate(items[index], pos + new Vector3(0, heightOffset, 0), items[index].transform.rotation, transform);
                }

                //Turns object to go in the direction of the bezier curve
                if (curveRotation)
                {
                    go.transform.forward = path.GetDirection(i * step);
                }
            }
        }