# Brewball: Help with Vectors

**URL:** <https://discourse.codecombat.com/t/brewball-help-with-vectors/6615>\
**Category:** Uncategorized\
**Created:** [January 28, 2016, 12:54pm UTC](https://discourse.codecombat.com/t/brewball-help-with-vectors/6615 "2016-01-28T12:54:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hinkle](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/hinkle/32/3967_2.png) [@Hinkle](https://discourse.codecombat.com/u/Hinkle)\
**Post date:** [January 28, 2016, 12:54pm UTC](https://discourse.codecombat.com/t/brewball-help-with-vectors/6615/1 "2016-01-28T12:54:06Z")

</div>

I am stuck on brewball. I am very effectively running somewhere offscreen that isn’t even in the same direction as the where the potion is going to land. I am not even trying to avoid the mines at this point.

```python
loop:
    potion = self.findFriendlyMissiles()[0]
    firetraps = self.findHazards()
    haz = self.findNearest(firetraps)
    omarn = self.findByType("potion-master")[0]
    if potion:
        dest = potion.targetPos;
        goal = Vector.subtract(dest, self.pos)
        goal = Vector.normalize(goal)
        goal = Vector.multiply(goal, 10)
        self.say(goal) #for debugging
        self.move(goal)
    else:
        if omarn and self.distanceTo(omarn) > 10:
            pass
        else:
            self.say("Hup, hup!")

```

![](https://cdck-file-uploads-us1.s3.dualstack.us-west-2.amazonaws.com/flex016/uploads/codecombat/original/2X/9/9ebe2bb9d3e4839b46bbfce07b4636e5743d65f5.png)

---

<div class="post-metadata">

**Author:** ![Catsync](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/catsync/32/6431_2.png) [@Catsync](https://discourse.codecombat.com/u/Catsync)\
**Post date:** [January 28, 2016, 3:23pm UTC](https://discourse.codecombat.com/t/brewball-help-with-vectors/6615/2 "2016-01-28T15:23:27Z")

</div>

I’m still sketchy on vectors sometimes myself, but here’s a way to think of it that I think is accurate 🙂

Your `goal` variable contains instructions for how to move toward where the potion will land.

For example `{ x: 8, y: -5 }` meaning: to move toward the potion - take 8 steps right and 5 steps down.

If you do `self.move(goal)` you are now trying to move to the **point** `{ x: 8, y: -5 }` which is down off the map somewhere.

Instead, you want to figure out the point you should move to by starting from your hero’s current position, then adding the steps contained in `goal` with `Vector.add`.

---

<div class="post-metadata">

**Author:** ![sir-sonic-Destroyer](https://avatars.discourse-cdn.com/v4/letter/s/838e76/32.png) [@sir-sonic-Destroyer](https://discourse.codecombat.com/u/sir-sonic-Destroyer)\
**Post date:** [March 25, 2016, 3:57pm UTC](https://discourse.codecombat.com/t/brewball-help-with-vectors/6615/3 "2016-03-25T15:57:44Z")

</div>

can help here is my code:

```
loop:
    potion = self.findFriendlyMissiles()[0]
    firetraps = self.findHazards()
    # Remember that a Fire Trap will trigger if you move closer than 3 meters!
    omarn = self.findByType("potion-master")[0]
    if potion:
        dest = potion.targetPos
        # Go get the potion.
        if self.isReady("dash"):
            self.dash(potion.pos)
        else:
            self.move(potion.pos)
    else:
        if omarn and self.distanceTo(omarn) > 10:
            # Move back to Omarn.
            self.move(omarn.pos)
            # Warning: isPathClear doesn't work with Hazards!
        else:
            self.say("Hup, hup!")
```
