Brewball: Help with Vectors


#1

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.

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!")


#2

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

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.


#3

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!")