[Solved] Circle Walking

This is my code, my hero walks in a straight line and hits the reindeer:

# Mirror your partner's movement around the center X mark.
# Vectors can be thought of as an x, y position
# Vectors can also represent the distance and direction between two positions

# use Vector.subtract(vector1, vector2) to find the direction and distance from vector2 to vector1
# use Vector.add(vector1, vector2) to find the position you get when you start from vector1 and follow vector2
# A unit's position is actually a Vector!
partner = hero.findByType("peasant")[0]
Vector.subtract(partner.pos, hero.pos)
Vector.add(hero.pos, partner.pos)
# Create a new Vector at the center X point
center = Vector(40, 34)

while True:
    # First, you want to find the Vector (distance and direction) of the partner's position to the center X.
    vector = Vector.subtract(center,partner.pos)

    # Second, find the position your hero should moveTo starting from center, and following vector.
    moveToPos = Vector.subtract(vector, hero.pos)

    # Third, move to the moveToPos position.
    hero.move(moveToPos)
    pass

1 Like

The only two lines of code you need above the while true, are the partner= and center=. Since you are not defining a variable with the two Vector statements, they aren’t doing anything, actually.

In # First, you transposed the arguments.

In # Second, you don’t need the current position, which is hero.pos, but want the new position instead, which is center minus vector.

1 Like

So, like this:

 Mirror your partner's movement around the center X mark.
# Vectors can be thought of as an x, y position
# Vectors can also represent the distance and direction between two positions

# use Vector.subtract(vector1, vector2) to find the direction and distance from vector2 to vector1
# use Vector.add(vector1, vector2) to find the position you get when you start from vector1 and follow vector2
# A unit's position is actually a Vector!
partner = hero.findByType("peasant")[0]
Vector.subtract(partner.pos, hero.pos)
Vector.add(hero.pos, partner.pos)
# Create a new Vector at the center X point
center = Vector(40, 34)

while True:
    # First, you want to find the Vector (distance and direction) of the partner's position to the center X.
    vector = Vector.subtract(center,partner.pos)

    # Second, find the position your hero should moveTo starting from center, and following vector.
    moveToPos = Vector.subtract(vector, center - vector)

    # Third, move to the moveToPos position.
    hero.move(moveToPos)
    pass

1 Like

Not quite. You still have the arguments transposed in the vector = statement.

Two elements (arguments) need to be used for the moveToPos = formula. Those are ‘center’ and ‘vector’. The Vector.subtract statement is actually making a function call and it is the function that is performing the subtraction…you just need to tell it what to subtract from what.

1 Like

So, instead of the center - vector, I should use center

3 Likes

I solved it, wasn’t subtract, was add

2 Likes

So, you used Vector.add(???, ???) ?

2 Likes