How to move an object in to the corresponding mirrored coordinate (BGE)?

Suppose I have character surrounded by a cubic room.
My goal is to move that character to the opposite position of the room every time the character reaches one of the walls, roof and floor both included.

Like in the classical game "Asteroids" but with the Z axis included.

It's already possible to print the position by using a game property (string) attached to this module:

def update(cont):
own = cont.owner

own["pos"] = str([round(v) for v in own.worldPosition])


But how do I create the interval able to move the character object to the desired position?

There is a .blend prototype hosted HERE.

Addendum 1): There is another prototype that can be found here:

For this second prototype if you press only the W key continuously, the character will move to the opposite side as intended. But, how does one achieve this integration?

• Why not just detect when the object reaches one edge, and set it's location to the other edge? – X-27 is done with the network Dec 23 '16 at 21:23
• You want to do something like if obj.location.x > room.right.x: obj.localtion.x = room.left.x – sambler Dec 24 '16 at 4:25

Sounds like a job for the modulo operator. The boundary size is hard coded here, so you can delete that boundary cube. Set the worldSize variable to the size you want the boundary to be:

def update(cont):
own = cont.owner

own["pos"] = str([round(v) for v in own.worldPosition])

worldSize = 10

own.worldPosition[0] = own.worldPosition[0] % worldSize
own.worldPosition[1] = own.worldPosition[1] % worldSize


And a screenshot for context: