Home Technical Talk

Spherical world - how?

Hey there fellow polycounters,

At the company I work on we're making a Unity game where the enemies come from the top to the bottom of the screen linearly and the player can pan the camera from the top to bottom, just like an RTS game. (no sideways movement though)
I suggested having a spherical world so the enemies would appear from behind the horizon.
But then I don't know which would be the best way to implement that. Do you guys have any ideas?

Here's some reference:
[ame="http://www.youtube.com/watch?v=ga8Kh1N1PdQ"]Academy of Champions: Soccer (Wii) Full match gameplay - YouTube[/ame]

Replies

  • Justin Meisse
    Options
    Offline / Send Message
    Justin Meisse polycounter lvl 18
    I believe you can do all that in code. I'm not a programmer so I don't know how it works, you make the world in the traditional manner and then code magic makes it curved. I found this guy's tutorial on doing a cylinder world like Deathspank or Animal crossing link
  • Drew++
    Options
    Offline / Send Message
    Drew++ polycounter lvl 14
    ^ Correct.
    Could be done with a shader I believe... I think commander_keen did that in a little moon game he was working on.
  • commander_keen
    Options
    Offline / Send Message
    commander_keen polycounter lvl 18
    I think Justin_Meisse is refering to using a vertex shader to bend the world at runtime. That can be a good way of doing it, but because its a hack and the world isnt actually round it introduces a lot of problems and makes things more complicated. For what your describing why not just actually model the world as a sphere?
  • Ashaman73
    Options
    Offline / Send Message
    Ashaman73 polycounter lvl 6
    Model the world as cube and use catmull subdivison to create an "sphere" from it. From an coding view, you still have an cube and you can then "unwrap" it to a 2d plane and can move and place objects on this plane with ease.
  • r_fletch_r
    Options
    Offline / Send Message
    r_fletch_r polycounter lvl 9
    Ashaman73 wrote: »
    Model the world as cube and use catmull subdivison to create an "sphere" from it. From an coding view, you still have an cube and you can then "unwrap" it to a 2d plane and can move and place objects on this plane with ease.

    Also aren't you going to get spatial distortion? also how do you pathfind?



    Keen: would it be possible to use a sphere as a navmesh? me and a mate of mine want to try this but we're both a bit green when it comes to game programming.
  • Justin Meisse
    Options
    Offline / Send Message
    Justin Meisse polycounter lvl 18
    I think Justin_Meisse is refering to using a vertex shader to bend the world at runtime. That can be a good way of doing it, but because its a hack and the world isnt actually round it introduces a lot of problems and makes things more complicated. For what your describing why not just actually model the world as a sphere?

    wouldn't treating everything as a flat world and curving it afterwords be easier than having to build the world as a sphere? Especially since the amount of curvature wouldn't be tied to the size of the world. That minecraft mod seems to sit on top of everything pretty fine:
    http://youtu.be/TKw18P65A2s
  • ambershee
    Options
    Offline / Send Message
    ambershee polycounter lvl 17
    I would do it with a vertex shader that affects everything. Because everything is in reality flat, it actually simplifies programming in the long run.
  • commander_keen
    Options
    Offline / Send Message
    commander_keen polycounter lvl 18
    It may simplify some things. For instance if you want projectiles to follow the curvature of the planet then that is automatically done for you. Raycasts will seem to be bent around the planet, which may or may not be a good thing depending on what your trying to do. You do have some other issues like mesh bounds. Because the mesh is offset it may be culled while its still actually onscreen because the engine thinks it is off screen. You can manually adjust bounding boxes for mesh renderers although im not sure how expensive that is to do per frame.

    If the actual curvature doesnt have to match the exact size of the planet the and the benefits outweigh the problems then its probably a good idea.

    r_fletch_r I havent looked into the builtin navmesh stuff, but I assume it only works on flat worlds. You would probably have to create custom path finding.
  • Ashaman73
    Options
    Offline / Send Message
    Ashaman73 polycounter lvl 6
    A vertex shader can curve a flat surface, but you can't wrap around a whole sphere (think about a plane wrapping around a sphere, it is really messy). Either take a sphere as base and use a proper coordination system (i.e. polar coords) or an other representation (unit vectors, quaternions).

    Or take a cube as base (think about texturing a sphere with a cube map).

    Disortions or messing around with coordination system could be a problem, best to think about the game concept first (what are the core features) and after that think about what representation would fit your features best. Don't choose a solution you can't wrap your mind around, choose something you can easily handle.

    Navigation meshes or waypoint system, both will work, but you need to modify it accordingly.
  • ambershee
    Options
    Offline / Send Message
    ambershee polycounter lvl 17
    If you don't do it in the vertex shader, and want very visible physical sphere worlds, expect to do a lot of programming to handle the custom environment D:
  • commander_keen
    Options
    Offline / Send Message
    commander_keen polycounter lvl 18
    Not really, you just have to handle gravity and orientation manually which is trivial.
  • ambershee
    Options
    Offline / Send Message
    ambershee polycounter lvl 17
    Firstly, that's really not trivial - and the more complex your physics simulation, the worse it's going to be. Doing it in a very simple sense is far from impossible, but there's a huge amount of work behind most games engines that simply assumes that gravity is a value in the Z-axis. If you're picking up an existing piece of tech, such as using Unity, Unreal, I suspect there'll be a bit of fight on your hands getting it to do exactly what you need it. Outside of that, you'll have to handle your own game physics manually, which is also a lot of work.

    Secondly, there are other horiffic issues to handle - for example how do you handle something as simple and fundamental as a trace in a non-planar space? This is just one little example of where you'd have to take a small, simple piece of maths and bend it into something far more painful.
  • commander_keen
    Options
    Offline / Send Message
    commander_keen polycounter lvl 18
    Why would you have to handle physics manually? All you have to do is apply gravity to objects which is an extremely simple formula. Beyond that you just have to keep a players feet pointed at the ground which is also very simple. In most cases you dont want bent raycasts (which you would be forced to have with vertex deformation). If you do want a bent raycast for some reason its easy enough to make a raycast wrapper that shoots multiple rays to simulate a bent ray.

    I think there is a misconception from people who havent used Unity. They assume its like these other engines that were designed for specific use only in their internal environment and require source code and lots of people to do some drastic changes. Unity is designed for public use and because of that every aspect of the api is open and extendable and can easily conform to pretty much any project.
  • ZacD
    Options
    Offline / Send Message
    ZacD ngon master
    Yay vertex shader example. [ame="http://www.youtube.com/watch?v=THqYdFIS2GQ"]Round earth, Borderlands effect, Java priorities (Exodus Minecraft) - YouTube[/ame]
  • ambershee
    Options
    Offline / Send Message
    ambershee polycounter lvl 17
    Why would you have to handle physics manually? All you have to do is apply gravity to objects which is an extremely simple formula. Beyond that you just have to keep a players feet pointed at the ground which is also very simple. In most cases you dont want bent raycasts (which you would be forced to have with vertex deformation). If you do want a bent raycast for some reason its easy enough to make a raycast wrapper that shoots multiple rays to simulate a bent ray.

    I think there is a misconception from people who havent used Unity. They assume its like these other engines that were designed for specific use only in their internal environment and require source code and lots of people to do some drastic changes. Unity is designed for public use and because of that every aspect of the api is open and extendable and can easily conform to pretty much any project.

    There's more to game physics than 'gravity'. One example is collision detection between two objects and that as an example will rely on traces; and whilst you can get away with standard collision detection between objects that do not move a significant distance between frames as inaccuracy is probably within tolerable bounds (but only if the frame rate remains consistent and stable, which is not an assumption you should make), a fast moving object that can travel a considerable distance between frames will cause you issues.

    Lastly, you don't want to fake bent traces with multiple traces, you're just going to add needless cost and inaccuracy (you still need to be aware of the curvature in your simulation and that has to come from somewhere after all, although thankfully it should be constant). You're better off just using bent traces, which will be more accurate and given you're probably projecting spherically, more cost effective.

    If you're deforming verts in the vertex shader, you don't need bent traces like you're suggesting, because rendering occurs after game logic. Geometry is bent post-gameplay update, so after input, collision and resolution. The only thing you have to worry about is non-geometry like particle systems, but sprites and sprite emitters can be replaced with planar geometry instead.
  • commander_keen
    Options
    Offline / Send Message
    commander_keen polycounter lvl 18
    How does applying a spherical gravity force change how the physics engine works. Physics engines handle collisions between objects. It doesnt matter where those objects are or what is "up".

    Why does a spherical world mean you want spherical raycasts? Thats not realistic and its just weird. If you want everything to actually be flat but look round then you should probably be using a shader to make it look that way, but in most cases if you want a round world, you actually want it to be round. If you were to do it with a shader you would have to create a inverted bent raycast to compensate for when you need a straight ray, for instance anything camera based.

    The pros/cons for both methods:

    Real Sphere:
    Pros:
    works like the real works, physically accurate.
    No need to strange work arounds for straight raycasts.
    Only way to actually represent an accurate spherical world.
    Cons:
    Manual gravity calculation (gravity/distance).
    Need to calculate "up" vector at every position.
    Make sure you are handling rotation math correctly to avoid problems at poles.



    Bent Vertices:
    Pros:
    Post effect, doesnt change any gameplay (if this is what you want).
    Can build worlds flat.
    Can use on structures that could not otherwise be bent into a sphere (minecraft world for example).
    Cons:
    Hard to understand if your not a programmer.
    Post effect, doesnt change any gameplay (if this is not what you want).
    Not real sphere and cannot represent an accurate spherical world.
    Frustum culling is broken without modifying all mesh bounds each frame.
    LoS through ground.
    Depending on the game most or all of your raycasts need to be inversely bent to counteract the curvature done at render time.


    In the example video he posted it looks like vertex distortion would be a good idea because its a slight bend and doesnt have any effect on gameplay.

    The example he described has a sort of rts view. Gameplay is affected by the curvature, logical and visual LoS is blocked.
  • Justin Meisse
    Options
    Offline / Send Message
    Justin Meisse polycounter lvl 18
    It seems like he just wants a cool visual effect, instead of the enemies appearing off screen they appear over the curve of the planet. Look at Deathspank, if the world was actually modeled to match the curvature you could completely walk around it in a matter of seconds.
  • LoTekK
    Options
    Offline / Send Message
    LoTekK polycounter lvl 17
    The example he described has a sort of rts view. Gameplay is affected by the curvature, logical and visual LoS is blocked.
    It's actually simpler than that, as I understood it. It's a linear vertical progression of enemies, so it sounds almost tower defense-y. Since you've got a fixed curvature, you already have a good idea of where LoS ends (approximation, obviously), in which case you can quite easily have any targeting methods ignore anything that's over the horizon (aka past a certain distance or outside an AABB).
  • Campaignjunkie
    Options
    Offline / Send Message
    Campaignjunkie polycounter lvl 18
    Hey, I'm making an FPS game with a spherical world in Unity. We don't use any vertex shaders or anything: we just build directly as if it's a spherical world. I wouldn't recommend using vertex shaders because that might actually be harder to build -- it wouldn't necessarily be WYSIWYG anymore.

    We use a rigidbody FPS controller as a base (don't use the normal character controller; it is axis-constrained to rotate only on Y) and just apply a force downwards, relative to the player. Once the player's hit the ground, we raycast down, and rotate the player to align with the ground normal. That's the basics and that's all you really need. If you google, I'm pretty sure there's a lot of code snippets you can use to learn / hack.
  • Bruno Afonseca
    It seems like he just wants a cool visual effect, instead of the enemies appearing off screen they appear over the curve of the planet. Look at Deathspank, if the world was actually modeled to match the curvature you could completely walk around it in a matter of seconds.

    ^ this!

    Thanks for all the responses guys! Really helped! I forwarded this to the coders and they're tinkering with it right now (atm in a vertex shader form). Happy to have sparked this discussion :) Really interesting solutions you got there!
  • warby
    Options
    Offline / Send Message
    warby polycounter lvl 18
    building stuff at angels is a huge pain in the ass if you can figure out how to do it with a vertex shader id use that !
  • almighty_gir
    Options
    Offline / Send Message
    almighty_gir ngon master
    wouldn't treating everything as a flat world and curving it afterwords be easier than having to build the world as a sphere? Especially since the amount of curvature wouldn't be tied to the size of the world. That minecraft mod seems to sit on top of everything pretty fine:
    http://youtu.be/TKw18P65A2s

    yes and no...

    if you consider that to curve a flat surface you basically have to multiply vertex positions by a radial amount, right? then the further from the center of the world you go, the futher apart verts are moved. the larger the world, the more visible this effect would be.

    but if you model your game world as a sphere, you don't need to apply that radial multiplication to all of the props etc. which means that they won't be stretched.
Sign In or Register to comment.