Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Move the world, or the onstacles?

Discussion in '2D' started by Dblfstr, Mar 6, 2014.

  1. Dblfstr

    Dblfstr

    Joined:
    Jan 17, 2014
    Posts:
    15
    Here is a question. (concerning and infinite side-scroller.. yes another one). Currently the only thing that truly moves, is my player. Of course the whole world moves with it. Everything except for the obstacles that is. So my player forward at a constant rate, The camera has a script that gets the players position every single update, and sets the camera position accordingly. This gets some pretty heavy use through out the game. Many things are then children of the camera. My graphical floor, the floor collider, the background, the intermediate background. The ceiling collider, basically my scene is a child of the Main camera. Then I have my obstacles, they are spawned from an Object pool at a specific distance ahead of the player, at a given time interval. The total obstacle has 3 parts, and then and audio source. My pool contains 6 prefabs, because no more than 5 are ever needed at one time (I put one more in there just in case.). Once the obstacle is off screen, it is added back to the pool.

    So my question, is it better (in this case) to have basically everything follow the player, (camera follow player, everything attached to camera); and my obstacles are stationary. OR should I let everything else be static, and have the obstacles, once they are active, move toward the player at some velocity?

    Sorry for the long question.
     
    Last edited: Mar 6, 2014
  2. SiegfriedCroes

    SiegfriedCroes

    Joined:
    Oct 19, 2013
    Posts:
    569
    I think it would be a lot better if everything is static and only the obstacles move. So you just have your player, level, camera,.. at the same position all the time (no need for anything to be child of the camera anymore) and then just spawn obstacles with a constant movement toward you till they are off screen again.
     
  3. Dblfstr

    Dblfstr

    Joined:
    Jan 17, 2014
    Posts:
    15
    What I really need to do, is try. Try having everything static, and only move the obstacles. Then I will really be able to see the difference in performance.
     
  4. SiegfriedCroes

    SiegfriedCroes

    Joined:
    Oct 19, 2013
    Posts:
    569
    I don't think there will be much difference in performance, it will just be more logical this way :)
     
  5. Dblfstr

    Dblfstr

    Joined:
    Jan 17, 2014
    Posts:
    15
    Well, I was asking from a performance standpoint. I thought that the camera getting the players position every update was quite expensive. I do agree it would be more logical. I just happened to end up this way from when I first started building my game. You know, the player moved forward like most 2D games. The whole world scrolled as it should. Then I ran into problems with the foreground and intermediate background scrolling... until everything was attached to the camera that followed the player. I do see now that it is not the best approach, but I had already built so much around this sort of activity. After thinking about it though. It would be simple to change. Just don't move the player. Remove the 'followScript' portion from the main camera, and add a Move() function to my obstacles. Should be easy. Funny how the ideas start to flow we you start talking about them.