Serpent Savings Help


#1

I need some help with serpent savings. I try to make my peasant to move to the coin with vectors, but it’s not working. This is my code.

while (true) {
var friends = this.findFriends();
var tails = this.findEnemies();
var coins = this.findItems();
for (var i = 0; i < friends.length; i++) {
    var friend = friends[i];
    var coin = friend.findNearest(this.findItems());
    var goal = new Vector(coin.pos.x, coin.pos.y);
    var vectorToCoin = Vector.subtract(goal, friend.pos);
    vectorToCoin = Vector.normalize(vectorToCoin);
    vectorToCoin = Vector.multiply(vectorToCoin, 10);
    if (tails.length > 0) {
        for (i = 0; i < tails.length; i++) {
            var tail = tails[i];
            var tailToMe = Vector.subtract(friend.pos, tail.pos);
            Vector.normalize(tailToMe);
            Vector.multiply(tailToMe, 10);
            vectorToCoin = Vector.add(vectorToCoin, tailToMe);
        }
    }
    var moveToPos = Vector.add(friend.pos, vectorToCoin);
    this.command(friend, "move", moveToPos);
}

}