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
Could be done with a shader I believe... I think commander_keen did that in a little moon game he was working on.
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.
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
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.
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.
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.
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.
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.
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.
^ 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!
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.