Object Repeat on X and Z issue when camera is rotated


I’m trying to work out how to get Object Repeat on X & Z (if that’s the right description) to work. EG: In 2D / fixed camera it works like so

This works fine if I move the FreeCamera in the X and Z directions only and only when at angles 0, 90, 180, 270.

However if I rotate the camera to something inbetween I get a not suprising result, like so:

At first I move on Z - and + then I rotate camera by 90 deg and move in X +/-, then I rotate to something inbetween 0,90,180,270.

My code:

    let xDist = this.gallery.camera.position.x - this.item.position.x;
    let zDist = this.gallery.camera.position.z - this.item.position.z;

    // This will only for fixed camera and motion in x and z only
    // I need FreeCamera (1st person camera) motion in x and z only
    // I will be locking y to a min and max value limit.
    if (xDist < -100){
        this.item.position.x = this.gallery.camera.position.x - 99;

    if (xDist > 100){
        this.item.position.x = this.gallery.camera.position.x + 99;

    if (zDist < -100){
        this.item.position.z = this.gallery.camera.position.z - 99;

    if (zDist > 100){
        this.item.position.z = this.gallery.camera.position.z + 99;

I think this should be adding the camera’s rotation to the objects new position and using the camera as a centerpoint for that rotation…?

Any ideas…?

Sorry but I am not clear on what you are asking. Please provide a playground example and a description of what is happening and what you expect.

Ever play asteroids? The asteroid leaves one side of the screen and comes back in the other side but in the relative position based on exit location and direction, same thing.


Rotate camera click drag right, so box starts to angle upwards, note it should come back in on the left at same Y pos it exited. I’m trying to work out how to add the cameras rotation at any rotation or something like that so that the cube comes back into the scene at the appropriate position on the other side.

If I was to move towards that cube and then through it then past it, once it reaches distance limit it would then be brought back in, infront of the cmera at max distance. I need to handle all angles on x and z, I will be limiting the Y movement of the camera so meshe’s / primitives only need to move on x and z axis.