Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Move player or move the ground beneath him?

Discussion in 'Scripting' started by pony_pony_pony, Oct 19, 2021.

  1. pony_pony_pony

    pony_pony_pony

    Joined:
    May 14, 2021
    Posts:
    3
    Hi, I'm making a Crossy Road prototype. When player jumps I move the ground back and generate new piece of it in front of the player. So the player does not change his position.
    But in all tutorials I found developers make player moves with camera following him. Player moves in infinity.
    I was thinking that approach that I took is more appropriate for endless runners.
    So the exact question is: what is more appropriate and optimized way to create endless runner: move the ground with player does not change his position or let player actually go with camera attached to him? Or maybe it doesn't matter at all...
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,780
    There's another approach that may suit you: move the player and keep the ground constant, but periodically teleport everything "back" (whatever that means in your context) some distance, ground and player and everything.

    The main concern is you should remain within a few thousand units of (0,0,0) at all times, because the further you go, you begin to run out of precision in floating point land, and you will begin to see graphical artifacts such as jitter.

    To see what I mean, make a new scene, create and parent a few random visible GameObjects (Cubes, spheres, whatever) together, child a Camera to them to watch them clearly (zoom in), bolt a Rigidbody on them and let them drop. By the time they get to around -5000 you will begin to see jitter between them... the further they go, the worse it gets.
     
    _geo__ and pony_pony_pony like this.
  3. _geo__

    _geo__

    Joined:
    Feb 26, 2014
    Posts:
    1,115
    Another thing which might help you is to calculate how long your "runs" are (what's the maximum run distance).

    If you assume that your char runs with 10 units per second (that's 36 km/h = pretty fast) for a duration of 5 minutes then it would end at 3.000 (5 * 60 * 10). That's still okay I think. If your runs are sufficiently short then you can get away with just restarting every new run from 0. If your runs are long then you can look into what Kurt-Dekker suggested.
     
    pony_pony_pony likes this.
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,780
    And you can get TWICE that distance by starting your runs at negative half that distance!

    It is the magnitude difference away (plus or minus) from zero where less significant bits start getting dropped.

    It reminds me of going hiking until you're half tired, then turning around.
     
    exiguous, _geo__ and pony_pony_pony like this.
  5. pony_pony_pony

    pony_pony_pony

    Joined:
    May 14, 2021
    Posts:
    3
    Thanks a lot for clarifying
     
  6. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,356
    I would stick with the approach you have if it works for you you don't have to concern yourself with float precision as your player and therefore the camera remain in one place
     
  7. exiguous

    exiguous

    Joined:
    Nov 21, 2010
    Posts:
    1,749
    An "impressive" visualization of this can be seen here taken from here.
     
    Kurt-Dekker and _geo__ like this.
  8. _geo__

    _geo__

    Joined:
    Feb 26, 2014
    Posts:
    1,115
    Last edited: Oct 20, 2021
    exiguous likes this.