Exemplo n.º 1
0
        private void UpdateFireBeam(Vector2 toTarget, float width)
        {
            Vector2 beam = Vectors2.FromDegAngle(beamAngle, beamLength);

            float angle = Vector2.SignedAngle(beam, toTarget);

            if (angle != 0)
            {
                System.Func <float, float, float> minMax = angle > 0 ?
#pragma warning disable IDE0004 //Unity needs this because Unity is a little bitch
                                                           (System.Func <float, float, float>)Mathf.Min :
                                                           (System.Func <float, float, float>)Mathf.Max;
#pragma warning restore IDE0004
                float change = minMax(angle, aimSpeed *
                                      Time.deltaTime * (angle / (Mathf.Abs(angle))));

                beamAngle += change;
            }

            if (Raycast.TryRaycast2d(Pupil.position, beam,
                                     out RaycastHit2D hit2d, SelfOrbiter.Owner.body.Collider,
                                     SelfOrbiter.Collider))
            {
                beam = hit2d.point;
                float length = ((Vector2)Pupil.position - beam).magnitude;
                if (beamLength > length)
                {
                    beamLength = length;
                }

                HitTarget(hit2d, width);
                //HitParticles(hit2d, width);
            }
Exemplo n.º 2
0
    // Start is called before the first frame update
    void Start()
    {
        particles          = GetComponent <ParticleSystem>();
        transform.rotation = Quaternion.Euler(0, 0,
                                              -90 + Vectors2.TrueAngle(Vector2.right, Velocity));

        body.handler = this;
    }
Exemplo n.º 3
0
        private bool ShootTarget(EnemyController self, out float angle)
        {
            angle = 0;
            Vector2      vt        = self.target.transform.position;
            Vector2      pos       = self.transform.position;
            Vector2      direction = vt - pos;
            float        distance  = direction.magnitude;
            RaycastHit2D hit       = Physics2D.Raycast(pos + (direction.normalized
                                                              * (self.body.radius + 0.1f)), direction, distance);

            if (hit && hit.transform == self.target.transform)
            {
                angle = Vectors2.TrueAngle(Vector2.right, pos - vt);
                return(true);
            }

            return(false);
        }