Esempio n. 1
0
        private void CreateBolt(LineRenderer line)
        {
            //lineObject.material.SetTextureScale("_MainTex", new Vector2(distance * zigZagPerMeter, 1.0f));
            //lineObject.numPositions = vertexCount;

            float totalDistance = _pathComp.TotalDistance;
            int   numPositions  = Mathf.CeilToInt(totalDistance * zigZagPerMeter);

            Vector3[] points = new Vector3[numPositions];

            line.positionCount = numPositions;
            line.material.SetTextureScale("_MainTex", new Vector2(totalDistance * zigZagPerMeter, 1.0f));

            // set the ends
            points[0] = _pathComp.GetPathPoint(0.0f).point;
            points[numPositions - 1] = _pathComp.GetPathPoint(totalDistance).point;


            Vector2 previousOffset = Vector2.zero;

            for (int i = 1; i < numPositions - 1; i++)
            {
                Path_Point pathPoint = _pathComp.GetPathPoint(Math_Functions.Value_from_another_Scope(i, 0, numPositions - 1, 0, totalDistance));


                Vector2 offset = new Vector2(Random.Range(-1.0f, 1.0f), Random.Range(-1.0f, 1.0f));

                offset        *= zigZagIntensity;
                previousOffset = offset;

                points[i] = pathPoint.point + (pathPoint.right * offset.x) + (pathPoint.up * offset.y);
            }

            line.SetPositions(points);
        }
        void LateUpdate()
        {
            if (_particle_array == null)
            {
                Start();
                _path_comp.Update_Path();
            }
            else if (isPathUpdating)
            {
                _path_comp.Update_Path();
            }

            _numParticles = _particle_system.GetParticles(_particle_array);

            if (_numParticles > 0)
            {
                for (int i = 0; i < _numParticles; i++)
                {
                    ParticleSystem.Particle obj = _particle_array[i];

                    // This made it based on the particle lifetime
//					float normalizedLifetime = (1.0f - obj.remainingLifetime / obj.startLifetime);
//
//					if(hasRandomStartingPoints){
//						normalizedLifetime += Get_Value_From_Random_Seed_0t1(obj.randomSeed, 100.0f);
//						normalizedLifetime = normalizedLifetime % 1.0f;
//					}
//
//					Path_Point axis = _path_comp.GetPathPoint(_path_comp.TotalDistance * normalizedLifetime);

                    // This made it based on the paritcle speed
                    float dist = (obj.startLifetime - obj.remainingLifetime) * obj.velocity.magnitude;
                    if (hasRandomStartingPoints)
                    {
                        dist += Get_Value_From_Random_Seed_0t1(obj.randomSeed, 100.0f) * _path_comp.TotalDistance;
                    }
                    dist = dist % _path_comp.TotalDistance;

                    Path_Point axis = _path_comp.GetPathPoint(dist);

                    Vector2 offset = Vector2.zero;
                    if (pathWidth > 0)
                    {
                        offset  = Math_Functions.AngleToVector2D(obj.randomSeed % 360.0f);
                        offset *= Get_Value_From_Random_Seed_0t1(obj.randomSeed, 150.0f) * pathWidth;
                    }

                    _particle_array[i].position = axis.point +
                                                  (axis.right * offset.x) +
                                                  (axis.up * offset.y);
                }

                _particle_system.SetParticles(_particle_array, _numParticles);
            }
        }
Esempio n. 3
0
        private void Craft()
        {
            _path = GetComponent <PathComp>();
            Path_Point pointA = _path.GetPathPoint(0.0f);
            Path_Point pointB = pointA;


            for (float dist = 0.0f; dist < _path._path.TotalDistance; dist += _segment_length)
            {
                pointB = _path.GetPathPoint(Mathf.Clamp(dist + _segment_length, 0, _path._path.TotalDistance));

                _helpTransform1.rotation = Quaternion.LookRotation(pointA.forward, pointA.up);
                _helpTransform1.position = transform.TransformPoint(pointA.point);

                _helpTransform2.rotation = Quaternion.LookRotation(pointB.forward, pointB.up);
                _helpTransform2.position = transform.TransformPoint(pointB.point);

                Add_Segment();

                pointA = pointB;
            }
        }