Reset game objects and camera to 0,0 seamlessly (SOLVED)

In my infinite runner I want to periodically move all game objects and the camera back to 0,0 in game to avoid getting too far away from origin as the player progresses.

How can I do this without showing the wrong positions for one frame? As usual I’m using Orthographic camera.

I’ve attached a minimal example which shows the problem:

  1. Game object moves to a new location
  2. Once the animation is finished, the camera moves to the game object location.
  3. Both the camera and game object are moved back to 0,0.
  4. The ball moves back instantly, the camera lags one frame behind showing the game object in the wrong position for one frame.

ResetPositions.zip (227.7 KB)

1 Like

I would suggest keeping the camera fixed at origin (0,0,0) and instead move the objects.
E:g. spawn them out of camera, make them move past the camera, and when they moved far enough, remove them again

5 Likes

As soon as I read that, I knew I had some refactoring to do. :stuck_out_tongue_closed_eyes:

Works a charm. Thanks!

5 Likes

Follow up question! There is a particle trail following the player, and because I now move all game objects instead of the camera, the lingering particles don’t following the movement. Any ideas on how to deal with this?

Maybe change emitter space. Or use a custom particle solution (GOs and sprites are very efficient as long as draw calls are minimized).

Lazy option: Change ttl to a low number. :slight_smile:

1 Like