Exemple #1
0
        public static int Calculate(Vector3 start, Vector3 target, float maxVelocity, GrenadeDescription desc, Vector3[] buffer, float step = 0.05f)
        {
            if (buffer.Length == 0)
            {
                return(0);
            }

            buffer[0] = start;
            var count = 1;

            var currentVelocity = GetVelocity(start, target, maxVelocity, desc);
            var position        = start;
            var time            = 0f;

            Profiler.BeginSample("Grenade path");

            while (count < buffer.Length && time < desc.Duration && currentVelocity.magnitude > 0.1f)
            {
                Step(ref position, ref currentVelocity, step, desc.Gravity, desc.Bounciness);

                time           += step;
                buffer[count++] = position;
            }

            Profiler.EndSample();

            return(count);
        }
Exemple #2
0
        public static int Calculate(Vector3 start, float horizontalAngle, float angleInDegrees, float velocity, GrenadeDescription desc, Vector3[] buffer, float step = 0.05f)
        {
            if (buffer.Length == 0)
            {
                return(0);
            }

            buffer[0] = start;
            var count = 1;

            var horizontal = Quaternion.AngleAxis(horizontalAngle, Vector3.up) * Vector3.forward;
            var distance   = horizontal.magnitude;
            var angle      = angleInDegrees * Mathf.Deg2Rad;

            var currentVelocity = (horizontal.normalized * Mathf.Cos(angle) + Vector3.up * Mathf.Sin(angle)) * velocity;
            var position        = start;
            var time            = 0f;

            Profiler.BeginSample("Grenade path");

            while (count < buffer.Length && time < desc.Duration && currentVelocity.magnitude > 0.1f)
            {
                Step(ref position, ref currentVelocity, step, desc.Gravity, desc.Bounciness);

                time           += step;
                buffer[count++] = position;
            }

            Profiler.EndSample();

            return(count);
        }
Exemple #3
0
        public static Vector3 GetVelocity(Vector3 start, Vector3 target, float maxVelocity, GrenadeDescription desc)
        {
            var horizontal = new Vector3(target.x, 0, target.z) - new Vector3(start.x, 0, start.z);
            var height     = target.y - start.y;
            var distance   = horizontal.magnitude;

            float angle    = Mathf.Deg2Rad * 45;
            float velocity = maxVelocity;

            if (getAngle(height, distance, velocity, -desc.Gravity, ref angle))
            {
                if (angle > Mathf.Deg2Rad * 45)
                {
                    angle    = Mathf.Deg2Rad * 45;
                    velocity = getVelocity(height, distance, -desc.Gravity, angle);
                }
            }

            return((horizontal.normalized * Mathf.Cos(angle) + Vector3.up * Mathf.Sin(angle)) * velocity);
        }