Пример #1
0
 public override void attack(Vector3 target)
 {
     Vector3 p = transform.position;
     p.y = 0.5f + transform.position.y;
     Vector3 v = (target.toVector2XZ() - p.toVector2XZ())
         .toVector3XZ().normalized * bulletSpeed;
     StartCoroutine(attackCoroutine(p, v));
 }
Пример #2
0
 public override void chase(Vector3 destination)
 {
     Vector2 direction = destination.toVector2XZ() - transform.position.toVector2XZ();
     if (direction.magnitude > attackRange) {
         Vector3 des = (direction.normalized * attackRange).toVector3XZ() + transform.position;
         agent.SetDestination(des);
     } else
         agent.SetDestination(transform.position);
 }
Пример #3
0
    public override void attack(Vector3 target)
    {
        Vector3 position = transform.position;
        position.y = 1f + transform.position.y;
        Vector3 velocity;

        /* We need to find the velocity(direction) which can
         * possibly hit the moving target.
         * Assume the target will keep linear motion with the
         * current predicted velocity, then we have to find
         * the intersection of the target and the bullet being
         * shot.
         * Clearly, a possible hit may happen after t seconds.
         * the velocity of bullet is p / t + v, where
         * p is the position of the target relative to the
         * shooting point,
         * v is the predicted velocity of the target.
         * The motion of the bullet is described as a cone,
         * since we do not know the direction of it.
         * The cone is open along the time axis.
         * The motion of the target is described as a ray.
         * The problem become finding intersection of a cone
         * and a ray.
         * Equation of cone:
         * x^2 + z^2 = (speed^2)(t^2)
         * Equation of ray:
         * (x, t, z) = (p.x + v.x * t, t, p.z + v.z * t)
         * Substitution gives a quadratic equation to solve
         */

        Vector2 p = target.toVector2XZ() - transform.position.toVector2XZ();
        Vector2 v = predictedVelocity.toVector2XZ();
        float a = Vector2.Dot(v, v) - bulletSpeed * bulletSpeed;
        float b = 2.0f * Vector2.Dot(p, v);
        float c = Vector2.Dot(p, p);
        float r1, r2;
        if (Util.solveQuadratic(a, b, c, out r1, out r2) >= 0f
            && (r1 > 0f || r2 > 0f)) {
            float t;
            if (r1 > 0f && r2 > 0f)
                t = Mathf.Min(r1, r2);
            else
                t = Mathf.Max(r1, r2);
            Vector2 u = p / t + v;
            velocity = u.toVector3XZ().normalized * bulletSpeed;
        } else {
            velocity = p.toVector3XZ().normalized * bulletSpeed;
        }
        UniformMotion um = BulletFactory.CreateUniformMotionBullet(position, velocity, bulletLife);
        um.startMoving();
    }
Пример #4
0
 public virtual void chase(Vector3 destination)
 {
     Vector2 direction = destination.toVector2XZ() - transform.position.toVector2XZ();
     if (direction.magnitude > attackRange) {
         Vector3 des = (direction.normalized * attackRange).toVector3XZ() + transform.position;
         agent.SetDestination(des);
     } else {
         agent.SetDestination(transform.position);
         Quaternion targetRotation = Quaternion.LookRotation(direction.toVector3XZ());
         Quaternion newRotation = Quaternion.Lerp(transform.rotation,
                                                  targetRotation,
                                                  agent.angularSpeed * Time.deltaTime);
         transform.rotation = newRotation;
     }
 }
    private bool getMoveDir(out Vector2 dir, out Vector2 joystick_dir)
    {
        joystick_dir = new Vector2(Input.GetAxis(axis_horizontal_name), Input.GetAxis(axis_vertical_name));

        if (axis_high_pass > Mathf.Abs(joystick_dir.x) && axis_high_pass > Mathf.Abs(joystick_dir.y))
        {
            dir = Vector2.zero;
            return(false);
        }

        var temp_dir = new Vector3(joystick_dir.x, 0, joystick_dir.y);

        temp_dir = Quaternion.Euler(new Vector3(0, camera_controller.angles.y, 0)) * temp_dir;

        dir = temp_dir.toVector2XZ();
        dir.Normalize();
        return(true);
    }
 public Vector3 queryNewPosition(Vector3 p3, MechBlock.Direction d)
 {
     Vector2 p2 = fromWorldToGrid(p3.toVector2XZ());
     int row = (int) p2.x;
     int col = (int) p2.y;
     switch (d) {
     case MechBlock.Direction.EAST:
         p2 = grid.moveBlock(row, col, MechGrid.Direction.DOWN);
         break;
     case MechBlock.Direction.NORTH:
         p2 = grid.moveBlock(row, col, MechGrid.Direction.RIGHT);
         break;
     case MechBlock.Direction.SOUTH:
         p2 = grid.moveBlock(row, col, MechGrid.Direction.LEFT);
         break;
     case MechBlock.Direction.WEST:
         p2 = grid.moveBlock(row, col, MechGrid.Direction.UP);
         break;
     }
     p2 = fromGridtoWorld(p2);
     return p2.toVector3XZ();
 }
Пример #7
0
 public bool canLaunchAttack(Vector3 destination)
 {
     float distance = (destination.toVector2XZ() - transform.position.toVector2XZ()).magnitude;
     return (distance <= attackRange && attackIntervalTimer >= attackInterval);
 }
Пример #8
0
 public override void attack(Vector3 target)
 {
     Vector2 p = transform.position.toVector2XZ();
     Vector2 dir = target.toVector2XZ() - p;
     StartCoroutine(attackCoroutine(dir.normalized));
 }