Пример #1
0
        /// <summary>
        /// Stop this instance ans sets <see cref="currentPos"/> to 0.
        /// </summary>
        public void Stop()
        {
            if (pathMagic.waypoints.Length == 0)
            {
                return;
            }
            isPlaying  = false;
            currentPos = 0f;

            UpdateTarget(pathMagic.computePositionAtPos(currentPos), pathMagic.computeRotationAtPos(currentPos));
        }
Пример #2
0
        /// <summary>
        /// Physics computation of the joint
        /// </summary>
        void FixedUpdate()
        {
            if (connectedPath == null)
            {
                return;
            }

            // Re-align transform on path
            float minPos = computePosAtMinDistance();

            _tr.position = GetPositionForPos(minPos);

            //Debug.Log (GetPositionForPos (minPos));
            //Debug.DrawLine (_tr.position, GetPositionForPos (minPos), Color.cyan);

            if (followPathOrientation)
            {
                // Align rotation to the path
                Vector3    position = Vector3.zero;
                Quaternion rotation = Quaternion.identity;
                float      velocity = 1.0f;
                int        waypoint = 0;

                if (connectedPath.presampledPath)
                {
                    connectedPath.sampledPositionAndRotationAndVelocityAndWaypointAtPos(minPos, out position, out rotation, out velocity, out waypoint);
                }
                else
                {
                    rotation = connectedPath.computeRotationAtPos(minPos);
                }

                if (!connectedPath.disableOrientation)
                {
                    _tr.rotation = connectedPath.transform.rotation * rotation;
                }
            }

            // Computer direction vector
            Quaternion ffVq = connectedPath.GetFaceForwardForPos(minPos);
            Vector3    ffV  = ffVq * Vector3.forward;

            ffV = connectedPath.transform.TransformVector(ffV);

            // Constraint the velocity to the path direction
            _rb.velocity = Vector3.Dot(_rb.velocity, ffV) * ffV;

            //Debug.Log (minPos);

            // Apply motor force
            if (motor)
            {
                _rb.AddForce(ffV * motorForce);
            }
        }
Пример #3
0
        public void Generate()
        {
            if (count < 0)
            {
                count = 0;
            }

            List <GameObject> elements = new List <GameObject> ();

            for (int i = 0; i < count; i++)
            {
                if (i < transform.childCount)
                {
                    elements.Insert(i, transform.GetChild(i).gameObject);
                }
                else
                {
                    elements.Insert(i, Instantiate(target));
                    elements [i].transform.parent     = transform;
                    elements [i].transform.localScale = new Vector3(1, 1, 1);
                }
            }

            if (elements.Count < transform.childCount)
            {
                for (int i = transform.childCount - 1; i >= elements.Count; i--)
                {
                    DestroyImmediate(transform.GetChild(i).gameObject);
                }
            }

            for (int i = 0; i < elements.Count; i++)
            {
                float pos = startingFrom + (float)(1f / count * i) * (endTo - startingFrom);

                Vector3    position;
                Quaternion rotation;

                if (path.PresampledPath)
                {
                    float velocity;
                    int   waypoint;

                    path.sampledPositionAndRotationAndVelocityAndWaypointAtPos(
                        pos,
                        out position,
                        out rotation,
                        out velocity,
                        out waypoint);
                }
                else
                {
                    position = path.computePositionAtPos(pos);

                    rotation = path.computeRotationAtPos(pos);
                }

                elements [i].transform.position = path.transform.TransformPoint(
                    position
                    );

                elements [i].transform.rotation = transform.rotation * rotation;
            }
        }