Ejemplo n.º 1
0
        private void UpdatePosition()
        {
            if (moveByArc)
            {
                if (count < 1.0f && movingToPoint)
                {
                    count += moveSpeed * Time.deltaTime;

                    Vector3 m1 = Vector2.Lerp(startPosition, middlePoint, count);
                    Vector3 m2 = Vector2.Lerp(middlePoint, targetPosition, count);
                    transform.position = Vector2.Lerp(m1, m2, count);
                    var rotation = Vector2Utils.CalculateFacingToTarget(m1, m2).angle;
                    transform.rotation = rotation;
                }
            }
            else
            {
                if (transform.position != new Vector3(targetPosition.x, targetPosition.y, 0) && movingToPoint)
                {
                    transform.position = Vector3.Lerp(transform.position, targetPosition, Time.deltaTime * moveSpeed);
                }
                else
                {
                    movingToPoint = true;
                }
            }
        }
Ejemplo n.º 2
0
        private void ShootToTarget(Transform target)
        {
            var(angle, directionalVector) = Vector2Utils.CalculateFacingToTarget(transform.position, target.position);
            var instance = Instantiate(ShootingAbility.bullet, transform.position, angle);
            var rb       = instance.GetComponent <Rigidbody2D>();

            if (gunObject != null)
            {
                gunObject.transform.right = target.position - gunObject.transform.position;
                gunObject.transform.Rotate(new Vector3(0, 0, -90));
            }

            rb.velocity              = directionalVector * ShootingAbility.speed;
            instance.damage          = damage;
            instance.shooterCollider = shooterCollider;
            instance.shooterTag      = shooterTag;
        }