- Home /
Creating 3d planets with terrain and atmosphere
I am having a difficult time thinking about how to create planets that you can walk on that have terrain and an atmosphere. I have tried creating a very large sphere, but find myself falling off after about 45 seconds. Is there another method I could use that would allow me to walk around the planet and not fall off? Also how would I go about generating terrain, and an atmosphere? I'm fairly new to scripting in Unity3d so any help would be great! Thanks!
This might help:
Answer by Kos-Dvornik · Mar 03, 2014 at 08:10 AM
Try this procedural terrain tutorials: http://kostiantyn-dvornik.blogspot.com/2014/02/huge-amazing-unity-terrain-tutorial.html
Answer by aldonaletto · Aug 02, 2013 at 04:26 AM
You can't use the Unity terrain in this case: it's intended to create only horizontal terrains. The planets should be entirely created in a 3D editor like Blender, or you could modify the regular sphere mesh by script, like in the Procedural Examples project.
Anyway, in order to walk over a spherical surface you would need some special code - take a look at the question Walking On Walls, where a rigidbody character can walk over any surface.
Finally: what do you mean by "atmosphere"? Game characters don't breathe, thus they don't need any atmosphere! Do you mean a kind of fog? Or are you thinking about something like the gravitational field in Angry Birds Starwars? This is a totally different thing: this game simulates a gravitational field that only attracts objects that enter its range (and the field really looks a lot like an atmosphere).
Thanks for the great answer! By atmosphere, I meant like clouds and a sky that are different than seen in space. I have a space skybox(black with stars), but when landing on planet, I wanted it to change to a separate skybox that has a sky relative to the planet style
A possible solution is to use a skybox material based on the SkyboxBlended shader. This shader blends two different skyboxes: you could assign the space textures to the first set and the planet skybox textures to the second set, and change the _Blend parameter from 0 to 1 when the player approaches the planet surface. Have a specific SkyboxBlended material for each planet, all of them with the space skybox first, and switch the materials when the player is in outer space: since the first set is always the same, changing the material when the player is outside any planet won't be noticed.
Besides this, you could also paint a sphere with the clouds and atmosphere in a semi-transparent fashion and encapsulate the planet, so that the atmosphere could be seen from the outside (when landed, this sphere would become invisible since Unity renders only the outer side).
"Finally: what do you mean by "atmosphere"? Game characters don't breathe, thus they don't need any atmosphere!"
Actually you can make a code so they have to have air to breath, for the atmosphere I would use a trigger....
yeah but he wants to add the effect of realism who cares if he cant really breathe. It would look unnatural to have a planet with no atmosphere and planets we cant breathe on have atmospheres just made up of different gases he can then incorporate into his game.
Answer by TySim · Jan 13, 2016 at 06:55 PM
I am not sure if I understand what you are doing, but if it is like what I was trying a while ago, I may have a solution for you. First, you need two separate but similar objects. The world as seen from above, and the world you walk on. The easiest way to do this is to create a huge rectangle "Planet". This is your walk on surface. The top and bottom (poles) would not actually work like they should, but this can be modified by using code to simulate a step that would normally be a short distance to be a large distance on the map, or by modifying the terrain so that when a player is near the pole, a second form of map (rectangle in the opposite direction (90 degrees off from the original) is used.
Second, you create the massive sphere and place the terrain map you have (modified to a jpeg or other graphic and converted to a spherical) as the texture map for the sphere. In essence you are taking the terrain that is flat in the game and making it into a globe when high enough into the air.
This is now where the two different sky boxes come into play. Once a person gets above a certain level, the skybox for the clouds would switch to the star skybox, and the flat would switch to the globe (with perhaps a transparent version of an outside facing globe of the clouds skybox over the planet to still show the clouds.
I hope that makes sense and answers how to accomplish what you are trying to do. I am assuming you want the player in space to see a planet, fly towards it, go through the atmosphere and land on the planet to then interact with it.
Edit: For true realism, if you are using a compass for example, then the poles should be a single block with 4 blocks attached to them as such:
| 1 | 2 | 3 | 4 | | P |
Now when a player is on square P and they go "up" They head north to block 2. When they go "right" they go north to block 3. When they go "down" they head north to block 4. When they go left, they head north to block 1. Conversely, going down from any of the 4 blocks, puts them in block P on which ever side would be connected to that block from above.
When they go right from block 4, they go to block 1, and when they go left from block 1, they go to block 4 The next layer would have more wrapping blocks, offset and linked on the right and left edges etc...
The problem with that approach is that the terrain must be drawn programatically and there would be some artifacts or gaps that you'd have to watch for. So the first part of this post is the best way. I have found that swapping the maps at the 45 degree n/s latitude works best. Again though, it will take some work to make the transition not so notable. I would suggest that as someone gets to the 42 degree latitude that both maps be drawn on top of each other.
Also, forgot to mention that sides, or ends must attach depending on the orientation.