Endless Runner: Floating Origin: Solve Long Distance Glitches (Unity3D Tutorial)

Поделиться
HTML-код
  • Опубликовано: 19 дек 2024

Комментарии • 76

  • @MisterXeolan
    @MisterXeolan Год назад +1

    Wow, i was worrying for a while about this issue, and in the end, all it took was just a few lines of codes. Thanks for the video and your effort!

  • @sykoo
    @sykoo 4 года назад +7

    Loving this camera setup so far Matt! Keep up the great work.

    • @newbquesttv
      @newbquesttv  4 года назад

      Thanks Sam! Really appreciate that :)

  • @322ss
    @322ss 4 года назад +3

    Topic that hasn't been covered in many (any?) Unity tutorial - thanks Matt!

  • @neohelios77
    @neohelios77 2 года назад +1

    I made my own version of this before knowing that there was already a solution on the wiki (doh!) anyways I basically seperated everything into two groups "player" and "everything else" and modified the positions, much like you see here. meh.. .it "worked" I guess, but I think the wiki verison is probably alot more elegant, so I'll refactor to that solution. Still, i learned alot from this, thanks!!

  • @mattydidsomething
    @mattydidsomething 4 года назад +4

    While not relevant to me just yet, this is such a simple and great tutorial! Have a dream of big levels (as everyone does, I imagine) so good to see a practical implementation of dealing with the infamous floating origin point.
    Thanks -looking forward to seeing future videos!

    • @newbquesttv
      @newbquesttv  4 года назад

      Thanks very much Matt! Glad you found it useful!

  • @jakematchett8160
    @jakematchett8160 3 года назад +1

    Awesome video, I've been trying to a solution to float precision for days haha. Subbed

  • @ijidau
    @ijidau 4 года назад +14

    If anyone is using Cinemachine and wondering how to deal with smoothing when the origin is moved, you just need to use the OnTargetObjectWarped(Transform, Vector3) API as described here: bit.ly/2SaVgcC

    • @frillopolska1090
      @frillopolska1090 Год назад

      I'm realy dumb, could you explain how to use it? ;-;

    • @ijidau
      @ijidau Год назад

      @@frillopolska1090 when your target object is warped back to origin you call this method on the camera and you pass in the target object position and the position delta (a Vector3 which represents the amount the target's position changed when being reset to origin)

  • @GoodnightTitan
    @GoodnightTitan 3 года назад

    Thanks for this, I was already looking at using this script but your description of it was really helpful in understanding whats going on

  • @soundtrackreimagined1854
    @soundtrackreimagined1854 4 года назад +4

    How did you keep it from messing up the trail on your vehicle?

  • @3wGaming
    @3wGaming 4 года назад +3

    what about navmeshes? occlusion culls?

    • @newbquesttv
      @newbquesttv  4 года назад +2

      You'd need to use the newer navmesh tools to have them be part of the level pieces, not floating in scene. Importantly this approach won't work for every game type and architecture.

  • @austin-multicellular
    @austin-multicellular 3 года назад

    you are a godsend. I am making a game involving full scale planets, and this is just awesome. :)

  • @RobLang
    @RobLang 4 года назад +5

    This is a really timely video for me as I'm just getting into distance movement in my game! 👍👍👍

  • @tristunalekzander5608
    @tristunalekzander5608 4 года назад +5

    Great video. Out of curiosity, is this the industry standard way of avoiding floating point errors? It seems like it would be really complicated with multiplayer.

    • @PDJazzHands
      @PDJazzHands 4 года назад +5

      In multiplayer you would send a legitimate coordinate then in the game you just do the reset to render it, this is purely because digits on floating points are exactly that, a floating decimal point, once you start running out of numbers to express small numbers you end up with positions being snapped to bigger and bigger grids, like a ps1 game, so just place everything you received in multiplayer into a world empty then move it all so the camera or player is in the origin

    • @tristunalekzander5608
      @tristunalekzander5608 4 года назад

      @@PDJazzHands Oh, that's actually pretty simple. I don't have a lot of experience with multiplayer. Thanks!

  • @MattKander
    @MattKander 4 года назад +1

    Is this the same kind of logic that would apply for a larger open world game like Breath of the wild or Witcher 3? A constant resetting of the origin to optimize the amount of assets and in game objects?

  • @soerennielsen
    @soerennielsen 4 года назад +2

    Cool trick :-) ! The only way I've read about people avoiding floating point precision is to move everything else except the player. I guess the best method depends on each project. I could imagine this could get a bit hairy down the line with many different systems needing to adjust for the shift in position.

    • @newbquesttv
      @newbquesttv  4 года назад +1

      Thanks Søren! Yes, I actually did a Flappy Bird-like tutorial for Unity years ago where we used the "world moves around the player" approach that fakes the motion. I think it's probably the most optimized approach and for something like a Flappy Bird style game it works well. I think for something like this I would just find that approach a little weird and counter-intuitive to build around, and so this approach works for me. Like everything in games we need to find the thing that is both performant enough and easy enough to reason about and work with.
      Here's the Flappy Bird tutorial for those who are curious: ruclips.net/video/WWn4i5u2pWY/видео.html

  • @Farrukh3D
    @Farrukh3D 4 года назад +1

    Very nice video and an important topic. Good one.
    Thanks for sharing the project as well :)
    Yes, the link is working now! ;)

    • @newbquesttv
      @newbquesttv  4 года назад +1

      Ah thank you! I’ll check the link

    • @newbquesttv
      @newbquesttv  4 года назад +1

      Lol the car emoji was added as part of the link 😂 fixed now

  • @TheAbeinG
    @TheAbeinG 4 года назад +1

    Thanks, super good explanation and pace of the video. Good to follow. Keep it up!

  • @florianmisof1988
    @florianmisof1988 4 года назад

    Thank you so much! For some reason i could not get this to behave by myself, but now it finally works.

  • @_zero9343
    @_zero9343 4 года назад +1

    Outstanding Sir! I had yet to find anything helpful on the interwebs in regards to this issue. Perhaps now... a 1:4 scale solar system? G'Day-

  • @NishanGhoshgameshamelame
    @NishanGhoshgameshamelame 3 года назад +1

    Hey Matt, , I know 'handling floating origin with cinemachine' was out of scope for the video but could you just share some insight on the issue ? like what could be the work around or perhaps where to learn more on this issue...

    • @newbquesttv
      @newbquesttv  3 года назад

      hey yeah the problem is that Cinemachine has interpolation, so it does a crazy zoom when you reposition. What needs to happen is have Cinemachine reposition instantly with no smoothing. I'm sure it's possible I just haven't used CM enough to know how to do it.

    • @NishanGhoshgameshamelame
      @NishanGhoshgameshamelame 3 года назад

      @@newbquesttv Aight Matt, much thanks for the code though.

  • @macro3751
    @macro3751 3 года назад +1

    Nice
    This is just what i needed

  • @JulianRijken
    @JulianRijken 4 года назад +2

    Hey Matt, how would you keep the same Cinemachine Transitions? When moving the Cinemachine camera the transitions stay at the old position and the camera rotates to the old position first for blending. Would you know how to overwrite this? You also talked about this in the video but you said that it was a bit out of scope for this video.

  • @xaxababa6616
    @xaxababa6616 4 года назад +2

    So Matt do you recommend moving the player or the world for endless runners?

    • @newbquesttv
      @newbquesttv  4 года назад

      I think it really depends, for small 2D examples I've made we did it by moving the world. For this I think moving the player and resetting the world works. I'm not sure if there's an agreed upon true best practice.

  • @A.Y.11
    @A.Y.11 2 года назад +3

    I’m writing a space game so this is awesome to see! Previously I was normalising each object relative to zero each time the player progressed, but accruing a larger distance and doing it occasionally makes a lot more sense!
    Is this method viable for mobile? I don’t see why it wouldn’t be but your thoughts would be appreciated.

    • @newbquesttv
      @newbquesttv  2 года назад

      Like you I don't see why it wouldn't work for mobile, but haven't personally tested.

  • @xellart
    @xellart Год назад

    Another way to avoid this is to weigh your track pieces. After a radius of 1k for example, start giving the pieces that would take you further away from the origin less weight. This way the procedural track will always want to stay around the origin.

  • @ianjones9676
    @ianjones9676 4 года назад +2

    Instead of moving all root GameObjects, would parenting all GameObjects to an empty 'world' object and then moving this world object to reset the origin work?

    • @newbquesttv
      @newbquesttv  4 года назад

      I think so... unless having them under an empty world created other unknown issues

    • @zombievirals
      @zombievirals 3 года назад +2

      I did it this way and it works for me fine, except for my camera(my camera uses DoTween smoothing and all that so I have to figure a way around it).

  • @fmproductions913
    @fmproductions913 4 года назад +2

    Very useful video, thanks! I wonder if there is a viable solution if a game is played by multiple players at once. I'd imagine that the offset position can be calculated based on the average position of all players - but that would only work they are not too far apart.
    For online multiplayer, I'd think that it would be possible to each client shifts the world according to their own position, and that state updates don't have to be sent to other clients that are too far away to perceive the actions of this client.

    • @newbquesttv
      @newbquesttv  4 года назад

      Adding online multiplayer to this is a pretty big shift in paradigm. I think for an approach like that you'll probably need to be handling a simulation on the server that represents the world space positions of all the players and then running something like this (maybe) client side for each player to render and display the world. But honestly I've never done it so I'm just shooting from the hip in thinking about it.

    • @fmproductions913
      @fmproductions913 4 года назад +2

      @@newbquesttv Good point! That would indeed be necessary then. The local world positioning might still be useful to avoid visual glitches on the client side, but there certainly needs to be another solution for authoritative game state calculations

  • @AugoER
    @AugoER 4 года назад +2

    I got a problem. When I put this floating origin script on a camera of a first person controller or simple camera controller, and the one reaches the threshold, all of the objects in the scene start moving in one direction non stop (Terrains most of all). Would like to know from what you think. You got a pretty good looking game there man!

    • @newbquesttv
      @newbquesttv  4 года назад +3

      It sounds like not everything is getting moved so the distance check keeps getting triggered maybe?

  • @alpha3836
    @alpha3836 2 года назад +1

    So for some reason the trees on my terrain become really really small after using this script, can you explain why please?

  • @danielcreed2106
    @danielcreed2106 3 года назад

    I like this. Really is helping me in a project :D

  • @322ss
    @322ss 4 года назад +2

    Didn't know about Scene.GetRootGameObjects - that is pretty nice feature.

    • @newbquesttv
      @newbquesttv  4 года назад

      Thanks yeah me neither until doing this!

  • @adambenk0
    @adambenk0 4 года назад +1

    I used this script in my space game but the ship is still shaking, if I go really far away from the origin. It is reduced like by 1/2 but still horrible and noticeable.
    The entire scene moves with me correctly but there is still some shakiness.

  • @malfagaming7739
    @malfagaming7739 2 года назад

    Thank you for this endless runner series! If you don't mind I need help with a little issue. I made a custom cloud particle effect, and made it an exception on the floating origin script. But it still feels odd while playing, what would be your approach on this? Thanks again!

  • @newbquesttv
    @newbquesttv  4 года назад +2

    Grab the full project here: bit.ly/endlessracer

  • @tranceemerson8325
    @tranceemerson8325 3 года назад +1

    this is awesome, how quickly can it move thousands of objects to the origin? If your scene has a lot of objects, I can see a lot of lag spikes if you have too many. has anyone tested this?

  • @NotSuperSerious
    @NotSuperSerious 3 года назад

    How would you prevent particles set to world space from being left behind when everything moved?

  • @zombievirals
    @zombievirals 3 года назад

    This works great for me, except for my camera(I have a helicopter style camera movement that uses DoTween). The camera just smooths all the way back so to speak. I guess I would have to turn the smoothing off quickly and back on or something, we shall see! Thanks!!

  • @vast634
    @vast634 3 года назад +1

    This aproach gan leave the objects in wrong positions, as moving their position will always yield a small error. Better is to have all gameobjects be parented to a Scene-Origin empty object, and then just move this object. (no need to iterate over all objects then). You have to use "localPosition" in your scripts then.

    • @forasago
      @forasago 2 года назад

      Won't this break Unity physics? Rigidbodies are only supposed to be on root objects, not child objects. If all the objects are parented that means they can't have proper physics.

    • @vast634
      @vast634 2 года назад

      @@forasago If the parent is just an empty transform, it works fine. You also need to move this outside of a fixed update call.

  • @brappineau4161
    @brappineau4161 3 года назад

    Could you use this origin script to keep multiple players within spawned chunks? Or make a script to to identify who's in second and reset origin of player to 1st players chunk.
    Really need some help with this

    • @newbquesttv
      @newbquesttv  3 года назад +1

      This solution would work on the local client for the "world display" layer of a networked game. Not totally clear on your question though but this is not designed for a networked game in the example.

    • @brappineau4161
      @brappineau4161 3 года назад

      I'm a complete beginner. Was looking into networked play setup & traffic for endless runners. Can't seem to find any info on those two aspects

    • @newbquesttv
      @newbquesttv  3 года назад +1

      @@brappineau4161 tbh networking, especially in Unity is pretty tough, I'd start with non-network stuff and build up your skills first

  • @ashir.javed6
    @ashir.javed6 2 года назад

    Thank you sir

  • @danielmora7853
    @danielmora7853 3 года назад +1

    Great video, thank you so much for getting this information explained this clear. I was wondering if this can be applied to a 2d endless runner game where there are chunks of level spawned randomly as we descend? I will try just as in the video but it would be really nice if you take a look into it. Thanks again.

  • @NXiProduction
    @NXiProduction 3 года назад

    link to wiki not work, update please

  • @pygarg26
    @pygarg26 5 месяцев назад

    You’re saving me ths

  • @IneptOrange
    @IneptOrange 3 года назад

    Interestingly, this is what they do in Kerbal Space Program to get around inevitable floating point errors.