on('ready', function(){ const PIXELS = 70 on('chat:message', function(msg){ if(msg.type == 'api' && (playerIsGM(msg.playerid))) { if(msg.content.indexOf('!Drift')==0 || msg.content.indexOf('!drift')==0) { asteroids = findObjs({ name:"Asteroid" }, {caseInsensitive: false}); page = getObj("page",Campaign().get("playerpageid")); height = page.get("height"); heightString = height.toString(); //Only used for debugging width = page.get("width"); widthString = width.toString(); //Only used for debugging driftY = PIXELS; driftX = PIXELS; interval = 5; //Theese give a drift of between -2 and 2 so there offset = 3; //is a more dynamic drift than just one block. if (page.get('name').indexOf('Space')==0){ asteroids.forEach(function(asteroid){ courseX = randomInteger(interval)-(offset); courseY = randomInteger(interval)-(offset); deltaX = driftX * courseX; deltaY = driftY * courseY; if (asteroid.get('top')+deltaY > height*PIXELS + PIXELS) { //Above the map asteroid.set("top", height*PIXELS + PIXELS); //Stop it just off the map //asteroid.set("layer","gmlayer"); //Hide it //asteroid.set("top", 0) //Move it to the bottom of the map //asteroid.set("layer","objects"); //Unhide it } else if (asteroid.get('top')+deltaY < 0 - PIXELS) { //below the map asteroid.set("top", 0 - PIXELS); //Stop it just off the map //asteroid.set("layer","gmlayer"); //Hide it //asteroid.set("top", height*PIXELS); //Move it tot he top ot the map //asteroid.set("layer","objects"); //Unhide it } else { //Forces the y coordinate into a square if it has slipped out newY = (parseInt((asteroid.get('top') + deltaY) / PIXELS) * PIXELS) + PIXELS / 2; asteroid.set("top", newY); } if (asteroid.get('left')+deltaX > width * PIXELS + PIXELS) { //Off the right side asteroid.set("left", width * PIXELS + PIXELS); //Stop it just off the map //asteroid.set("layer","gmlayer"); //Hide it //asteroid.set("left", 0); //Move it to the left side //asteroid.set("layer","objects"); //Unhide it } else if (asteroid.get('left') + deltaX < 0 - PIXELS) { //Off the Left side asteroid.set("left", 0 - PIXELS); //Stop it just off the map //asteroid.set("layer","gmlayer"); //Hide it //asteroid.set("left", width*PIXELS); //Move it to the right side. //asteroid.set("layer","objects"); //Unhide it } else { //Forces the x coordinate into a square if it has slipped out newX = (parseInt((asteroid.get('left') + deltaX) / PIXELS) * PIXELS) + PIXELS / 2; asteroid.set("left", newX); } rotation = randomInteger(360); asteroid.set("rotation", rotation); //sendChat('Asteroid', "drifts " + deltaY + " x " + deltaX ); }) } //sendChat(asteroids.length + ' Asteroids', heightString*PIXELS + " x " + widthString*PIXELS ); } } }) }) When I had the commented out code in a player account could see off map asteroids zooming by in the background as they jumped accross the map to come in on the other side. I altered the code to make them just stop at the edge of the map, but still would prefer the other solution.