Пример #1
0
        private void UpdatePoints()
        {
            for (int i = 0; i < points.Count; i++)
            {
                SmokePoint point = points[i];

                // Natural smoke rise.
                point.Position += Vector3.up * RiseSpeed * Time.deltaTime;

                // Perlin noise. Needs to be remapped from (0 to 1) to (-1 to 1).
                float noiseX = Mathf.PerlinNoise(point.Age * PerlinPointCoefficient, Time.time * PerlinTimeCoefficient);
                float noiseY = Mathf.PerlinNoise(point.Age * PerlinPointCoefficient + 10f, Time.time * PerlinTimeCoefficient);
                float noiseZ = Mathf.PerlinNoise(point.Age * PerlinPointCoefficient + 20f, Time.time * PerlinTimeCoefficient);
                noiseX = -1 + noiseX * 2f;
                noiseY = -1 + noiseY * 2f;
                noiseZ = -1 + noiseZ * 2f;

                Vector3 noiseVel = new Vector3(noiseX, noiseY, noiseZ);
                noiseVel = new Vector3(noiseVel.x * PerlinAxisScale.x, noiseVel.y * PerlinAxisScale.y, noiseVel.z * PerlinAxisScale.z) * PerlinGlobalScale;

                // Apply perlin noise. Simulates the random swirls and twists in smoke trails, such as from a candle, or in this case a gun.
                point.Position += noiseVel * Time.deltaTime;

                // Increase age.
                point.Age += Time.deltaTime;

                points[i] = point;
            }
        }
Пример #2
0
        public SmokeTrail(Vector2 startPosition)
        {
            StartPosition = startPosition;

            for (int i = 0; i < vertices.Length / 2 + 1; i++)
            {
                SmokePoint smokePoint = new SmokePoint()
                {
                    Position     = StartPosition,
                    Acceleration = new Vector2(0, -0.05f),
                    Velocity     = new Vector2(0, -0.5f),
                    Friction     = new Vector2(1, 1)
                };
                smokePoint.Width = Random.Next(10, 20);

                Positions.Add(smokePoint);
            }

            MaxTime3 = Random.Next(1500, 8000);
            MaxTime  = Random.Next(150, 800);
        }