Exemplo n.º 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
            //);
        }
Exemplo n.º 2
0
        public override bool GameUpdate()
        {
            age += Time.deltaTime;
            Vector3 p = launchPoint + launchVelocity * age;

            p.y -= 0.5f * 9.81f * age * age;
            if (p.y <= 0f) //땅에 닿으면 반환
            {
                DefenseGame.SpawnExplosion().Initialize(targetPoint, blastRadius, damage);
                OriginFactory.Reclaim(this);
                return(false);
            }

            transform.localPosition = p;

            Vector3 d = launchVelocity;

            d.y -= 9.81f * age;
            transform.localRotation = Quaternion.LookRotation(d);

            DefenseGame.SpawnExplosion().Initialize(p, 0.1f); //explosion을 재사용해서 trail로 사용함
            return(true);
        }
Exemplo n.º 3
0
 private void OnEnable()
 {
     instance = this;
 }