Beispiel #1
0
            public void Update(GameObject cruiser, GameObject target)
            {
                if (cruiser == null)
                {
                    return;
                }

                if (timer > 0)
                {
                    timer -= 1 * Time.deltaTime;
                }
                else
                {
                    timer = Random.Range(minReflex, maxReflex);

                    float angle = 0;

                    if (target)
                    {
                        angle = Math2DHelpers.GetAngle(target, cruiser);
                    }
                    else
                    {
                        angle = Random.Range(0, 359) * Mathf.Deg2Rad;
                    }

                    _speed += Random.Range(minSpeed, maxSpeed) * new Vector3(Mathf.Cos(angle), Mathf.Sin(angle));
                }

                cruiser.transform.position += _speed * Time.deltaTime;

                _speed.x *= .99f;
                _speed.y *= .99f;
            }
Beispiel #2
0
            public void Update(GameObject magnet, GameObject target)
            {
                if (magnet == null)
                {
                    return;
                }
                if (target == null)
                {
                    return;
                }

                var angle    = Math2DHelpers.GetAngle(target, magnet);
                int distance = (int)(Mathf.Abs(target.transform.position.x - magnet.transform.position.x) + Mathf.Abs(target.transform.position.y - magnet.transform.position.y));

                if (distance > 0)
                {
                    _speed.x += Mathf.Cos(angle) * (int)(range / distance) * speed * Time.deltaTime;
                    _speed.y += Mathf.Sin(angle) * (int)(range / distance) * speed * Time.deltaTime;
                }

                if (_speed.x > maxSpeed)
                {
                    _speed.x = maxSpeed;
                }
                if (_speed.x < -maxSpeed)
                {
                    _speed.x = -maxSpeed;
                }
                if (_speed.y > maxSpeed)
                {
                    _speed.y = maxSpeed;
                }
                if (_speed.y < -maxSpeed)
                {
                    _speed.y = -maxSpeed;
                }

                magnet.transform.position += globalPolarity * polarity * _speed * Time.deltaTime;

                if (friction != 0)
                {
                    _speed *= 1 / (1 + (Time.deltaTime * friction));
                }
            }
Beispiel #3
0
        public static void Aim(GameObject bullet, GameObject target, float speed, Vector3 position = default)
        {
            if (position != default)
            {
                bullet.transform.position = position;
            }

            bullet.SetActive(true);

            var bulletBase = bullet.GetComponent <BulletBase>();

            if (bulletBase == null)
            {
                bulletBase = bullet.AddComponent(typeof(BulletBase)) as BulletBase;
            }

            var angle = Math2DHelpers.GetAngle(target, bullet);

            bulletBase.transform.rotation = Quaternion.Euler(0, 0, angle * Mathf.Rad2Deg);
            bulletBase.velocity           = new Vector3(Mathf.Cos(angle) * speed, Mathf.Sin(angle) * speed);
        }