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

Question about Infinite 2d level

Discussion in 'Getting Started' started by Al3XXX, Jan 25, 2015.

  1. Al3XXX

    Al3XXX

    Joined:
    Jul 13, 2014
    Posts:
    9
    Hi, I want to make 2d game with infinite level:
    Player is round stone RigidBody2D which can be manipulated by AddForce (by tapping on button).
    Level is segmented. These tiles are created with Instantiate before Stone and then will be destroyed by "Destroy" after.

    Can anybody recommend a sequence of actions, how best to do it.

    I think what it will be correct to make stone fixed and move only level. Or may be teleport ball(and level)to (0,0) coordinates and save it's velocity(but how?).
    (now i have moving stone, but i think it's a bad idea to move away far from the origin. I think it will cause bugs if the level is very long.)

    Sorry for my English.
     
  2. Al3XXX

    Al3XXX

    Joined:
    Jul 13, 2014
    Posts:
    9
  3. jwatte-imvu

    jwatte-imvu

    Joined:
    Jan 26, 2015
    Posts:
    6
    If you want the ball's reaction to the physical world to be physical, you cannot make the ball "stand still" in the physical coordinate space.

    What I would look at would be to set a "cell size" -- say, a 1000x1000 cell, where when the ball hits the 500 mark or -500 mark, offset the world (and the ball) by 500 in the appropriate direction. This means something like:
    - for each physical entity
    -- save velocity and angular velocity
    -- set the position the the updated position
    -- re-set the velocity and angular velocity values to the saved values, in case the position update re-direct a large velocity of some sort

    Depending on how physics is implemented internally, you may not even need to do the save/restore parts.
    Look for example at Rigidbody.position:
    Changing the position of a Rigidbody object by setting its transform.position value will cause it to "teleport" directly to the new position​

    Separately, you can focus the camera on the ball, so that, to the player, it "feels" as if the ball is the center of the universe.
     
    Al3XXX likes this.