Circle Walking Bug?

I’m probably just very bad at coding…
All my character does is walk in a straight line.

        // 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
    
    // Create a new Vector at the center X point
    var center = new Vector(40, 34);
    
    // A unit's position is actually a Vector!
    var partner = this.findByType("peasant")[0];
    loop {
        // First, you want to find the Vector (distance and direction) of the partner's position to the center X.
       var vector = Vector.subtract(center, partner);
    
        // Second, find the position your hero should moveTo starting from center, and following vector.
      var moveTo = Vector.add(center, vector);
    
        // Third, move to the moveToPos position.
    this.move(moveTo.pos);
    }

moveTo is already a position. You should use this.move(moveTo).


I wonder this even compiles, as moveTo shouldn’t even have a pos-attribute.

It just says that I should move to a {x:number, y:number} position…

Ah, got it. You need to use your partners position in the Vector.subtract, not your partner.

var vector = Vector.subtract(center, partner.pos);
var moveTo = //...

Thank you, it worked!!!

Any idea why this.move(moveTo.pos); make my hero run to into the right wall?? I had to use:
this.move({x: moveTo.x, y: moveTo.y});

Apparently, moveTo is already a position, so you can probably just use this.move(moveTo).

2 Likes

Thanks @ChronistGilver, and especially @J_F_B_M for pointing this out already :blush: