setxform after sensor collision creates real collision

Hello,
I'm implementing a wrap around screen. I've set up horizontal and vertical sensors around the edges (just outside the visible screen area), they are 0.1xworld height/width.

When I get a collision with the sensor and the object is travelling in the correct direction (to avoid it raising a collision again on the other side) I set a flag and after the world step I call setxform to position the object on the other side of the screen (and past the sensor).

What is happening is after I call setxform the object thinks it has hit something (no matter where on the vertical plane) and bounces back a little. It then lets the object carry on as normal.

It creates the bounce back wherever I call setxform. In the picture below/attached when the green ball (number 1) hits the sensor on the left I call setxform after world step and position it at position 2. It then thinks it has collided with the dotted line and bounces back before continuing as normal.

If I remove the sensors and just check for the object's position followed by calling setxform, all is well.

It's as if after I call setxform it thinks it has still collided with the left hand sensor but it is a real body.


Any idea?
I've removed as much code as I can and there's nothing going on in my code to alter anything and I've left box2d to the basics (only the sensors and one body exist in the world) and it's still happening. Without knowing any more, I've just given up and coded the wrap without using sensors.
Perhaps it is because you are changing the position during the actual collision processing. Have you tried caching the event and setting the object's position after Box2d is done with the frame?

Original thread: https://box2d.org/forum/viewtopic.php?t=2691