Exemple #1
0
        public void Launch(TargetPoint target)
        {
            Vector3 launchPoint = mortar.position;
            Vector3 targetPoint = target.Position;

            targetPoint.y = 0f;

            Vector2 dir;

            dir.x = targetPoint.x - launchPoint.x;
            dir.y = targetPoint.z - launchPoint.z;
            float x = dir.magnitude;
            float y = -launchPoint.y;

            dir /= x;

            float g  = 9.81f;
            float s  = launchSpeed;
            float s2 = s * s;

            float r        = s2 * s2 - g * (g * x * x + 2f * y * s2);
            float tanTheta = (s2 + Mathf.Sqrt(r)) / (g * x);
            float cosTheta = Mathf.Cos(Mathf.Atan(tanTheta));
            float sinTheta = cosTheta * tanTheta;

            mortar.localRotation =
                Quaternion.LookRotation(new Vector3(dir.x, tanTheta, dir.y));

            //SpawnSHell method는 defensegame안에 있고, initialize는 shell이 가지고 있음
            DefenseGame.SpawnShell().Initialize(launchPoint, targetPoint,
                                                new Vector3(s * cosTheta * dir.x, s * sinTheta, s * cosTheta * dir.y),
                                                shellBlastRadius, shellDamage);

            //Vector3 prev = launchPoint, next;
            //for (int i = 1; i <= 10; i++)
            //{
            //    float t = i / 10f;
            //    float dx = s * cosTheta * t;
            //    float dy = s * sinTheta * t - 0.5f * g * t * t;
            //    next = launchPoint + new Vector3(dir.x * dx, dy, dir.y * dx);
            //    Debug.DrawLine(prev, next, Color.blue, 1f);
            //    prev = next;
            //}

            //Debug.DrawLine(launchPoint, targetPoint, Color.yellow);
            //Debug.DrawLine(launchPoint, targetPoint, Color.yellow);
            //Debug.DrawLine(
            //    new Vector3(launchPoint.x, 0.01f, launchPoint.z),
            //    new Vector3(launchPoint.x + dir.x * x, 0.01f, launchPoint.z + dir.y * x),
            //    Color.white, 1f
            //);
        }
        public void Initialize(Vector3 position, float blastRadius, float damage = 0f)
        {
            if (damage > 0f)
            {
                TargetPoint.FillBuffer(position, blastRadius);
                for (int i = 0; i < TargetPoint.BufferedCount; i++)
                {
                    TargetPoint.GetBuffered(i).Enemy.ApplyDamage(damage); //damage apply를 여기서 하도록 함
                }
            }

            transform.localPosition = position;
            scale = 2f * blastRadius;
        }
Exemple #3
0
        protected bool TrackTarget(ref TargetPoint target)
        {
            if (target == null)
            {
                return(false);
            }
            Vector3 a = transform.localPosition;
            Vector3 b = target.Position;
            float   x = a.x - b.x; //높이 차이 무시하고 계산
            float   z = a.z - b.z;
            float   r = targetingRange + 0.125f * target.Enemy.Scale;

            if (x * x + z * z > r * r) //enemy sphere collider의 radius
            {
                target = null;
                return(false);
            }

            return(true);
        }