function findSoldierOffset(soldiers, i) {
var soldier = soldiers[i];
var angle = i * 360 / soldiers.length;
return radialToCartesian(5, angle);
}
// This function does the math to determine the offset a soldier should stand at.
function radialToCartesian(radius, degrees) {
var radians = Math.PI / 180 * degrees;
var xOffset = radius * Math.cos(radians);
var yOffset = radius * Math.sin(radians);
return {x: xOffset, y: yOffset};
}
var peasant = hero.findByType("peasant")[0];
// Use findByType to get an array of your soldiers.
while(true) {
// Use a for-loop to iterate over your array of soldiers.
var soldiers = hero.findByType("soldier");
for(var i = 0; i < soldiers.length; i ++) {
var soldier = soldiers[i];
var offset = findSoldierOffset(soldiers, i);
var offsetX = peasant.pos.x + offset.x;
var offsetY = peasant.pos.y + offset.y;
var position = {"x": offsetY, "y": offsetY};
hero.command(soldier, "move", position);
}
// Find the offset for a soldier.
// Add the offset.x and offset.y to the peasant's pos.x and pos.y.
// Command the soldier to move to the new offset position.
// The hero should keep pace with the peasant!
hero.move({x: hero.pos.x + 0.2, y: hero.pos.y});
}

So the problem is that the soldiers are stop moving in the middle.

These lines arenâ€™t needed, you can put these on one line. Use your var position to store the peasant.pos.x + offset.x and the peasant.pos.y + offset.y in the var position and command your soldier to move to â€śpositionâ€ť apart from that your code is right.

Hello and welcome to codecombat discourse! This is a cozy forum where you can share ideas, share fan art, get assistance for code, etc! Before you proceed, we hope that you review this topic, which shows all essentials of this board! Thanks!

Im running out of time but i tried to complete the level. I need to complete it for school

function findSoldierOffset(soldiers, i) {
var soldier = soldiers[i];
var angle = i * 360 / soldiers.length;
return radialToCartesian(5, angle);
}
function radialToCartesian(radius, degrees) {
var radians = Math.PI / 180 * degrees;
var xOffset = radius * Math.cos(radians);
var yOffset = radius * Math.sin(radians);
return {x: xOffset, y: yOffset};
}

var peasant = hero.findByType(â€śpeasantâ€ť)[0];

while(true) {

var soldiers = hero.findByType("soldier");
for(var i = 0; i < soldiers.length; i ++) {
var soldier = soldiers[i];
var offset = findSoldierOffset(soldiers, i);
var x = offset.x + peasant.pos.x;
var y = offset.y + peasant.pos.y;
hero.command(soldiers, "move", {'x': x, 'y': y});
}
hero.move({x: hero.pos.x + 0.2, y: hero.pos.y});