예제 #1
0
        private bool RaycastEnemy(HealthManager hm)
        {
            if (!Summoner.CheckEnemyValid(hm))
            {
                return(false);
            }

            // Cursed
            if (hm.tag == "Hatchling Magnet")
            {
                return(true);
            }

            RaycastHit2D raycast = Physics2D.Raycast(
                transform.position + Vector3.up * 1.5f,
                hm.transform.position - transform.position,
                Vector2.Distance(transform.position, hm.transform.position),
                1 << (int)PhysLayers.TERRAIN);

            return(raycast.collider == null || raycast.collider.gameObject.GetComponentInSelfChildOrParent <HealthManager>());
        }
예제 #2
0
        private void Update()
        {
            if (Ref.Hero == null)
            {
                return;
            }

            lineTimer -= Time.deltaTime;

            if (lineTimer <= 0)
            {
                lineTimer = TIMER_MAX;
                linePositions.Enqueue(transform.position);
                linePositions.Dequeue();

                line.SetPositions(linePositions.ToArray());
            }

            if (target == null)
            {
                target = Enemies.GetClosest(Summoner.CheckEnemyValid, AGGRO_RANGE);
            }

            if (!Summoner.CheckEnemyValid(target))
            {
                target = null;
            }

            if (target != null)
            {
                float dist = Vector2.Distance(Ref.Hero.transform.position, target.transform.position);
                if (target.isDead || target.hp <= 0 || dist > AGGRO_RANGE)
                {
                    target = null;
                }
                else
                {
                    transform.position = Vector3.MoveTowards(transform.position, target.GetComponent <Collider2D>().bounds.center, 20f * Time.deltaTime);
                    return;
                }
            }

            if (Vector2.Distance(Ref.Hero.transform.position, goal) > DRIFT_RANGE || Vector2.Distance(transform.position, goal) < 0.25f)
            {
                float r     = DRIFT_RANGE / 1.5f * (float)Math.Sqrt(rnd.NextDouble());
                float theta = (float)(rnd.NextDouble() * 2 * Math.PI);

                goal.x = Ref.Hero.transform.position.x + r * (float)Math.Cos(theta);
                goal.y = Ref.Hero.transform.position.y + r * (float)Math.Sin(theta);
            }

            if (transform.position.x < goal.x && velocity.x < MaxSpeed)
            {
                if (velocity.x > 1f && Math.Abs(transform.position.x - goal.x) < 0.5f)
                {
                    velocity.x -= Time.deltaTime * Acceleration * 2;
                }
                else
                {
                    velocity.x += Time.deltaTime * Acceleration;
                }
            }
            else if (transform.position.x > goal.x && velocity.x > -MaxSpeed)
            {
                if (velocity.x < -1f && Math.Abs(transform.position.x - goal.x) < 0.5f)
                {
                    velocity.x += Time.deltaTime * Acceleration * 2;
                }
                else
                {
                    velocity.x -= Time.deltaTime * Acceleration;
                }
            }

            if (transform.position.y < goal.y && velocity.y < MaxSpeed)
            {
                if (velocity.y > 1f && Math.Abs(transform.position.y - goal.y) < 0.5f)
                {
                    velocity.y -= Time.deltaTime * Acceleration * 2;
                }
                else
                {
                    velocity.y += Time.deltaTime * Acceleration;
                }
            }
            else if (transform.position.y > goal.y && velocity.y > -MaxSpeed)
            {
                if (velocity.y < -1f && Math.Abs(transform.position.y - goal.y) < 0.5f)
                {
                    velocity.y += Time.deltaTime * Acceleration * 2;
                }
                else
                {
                    velocity.y -= Time.deltaTime * Acceleration;
                }
            }

            velocity.x = Mathf.Clamp(velocity.x, -MaxSpeed, MaxSpeed);
            velocity.y = Mathf.Clamp(velocity.y, -MaxSpeed, MaxSpeed);

            transform.position += (Vector3)velocity * Time.deltaTime;

            if (Vector2.Distance(transform.position, Ref.Hero.transform.position) > 25f)
            {
                transform.position = Ref.Hero.transform.position;
            }
        }