diff --git a/script.js b/script.js index ed35737..35be137 100644 --- a/script.js +++ b/script.js @@ -308,8 +308,10 @@ function animate() { // Animate the grid with robot movement let offsetSpeedDivisor = (100 - gridSquareSize <= 0 ? 1 : 100 - gridSquareSize); console.log(offsetSpeedDivisor); - xGridOffset = (xGridOffset + (xSpeed / offsetSpeedDivisor) % gridSquareSize); - yGridOffset = (yGridOffset + (ySpeed / offsetSpeedDivisor) % gridSquareSize); + + // Accumulate grid offset and wrap it to create infinite grid effect + xGridOffset = (xGridOffset + (xSpeed / offsetSpeedDivisor)) % gridSquareSize; + yGridOffset = (yGridOffset + (ySpeed / offsetSpeedDivisor)) % gridSquareSize; // Accumulate robot rotation based on turn speed (convert to radians) robotRotation += turnSpeed * 0.01; // Scale factor for reasonable rotation speed