11
2013
Scorched Earth Terrain (wip)
This is another thing that i’ve always wanted to try in Unity, Scorched Earth deformable collapsing terrain (youtube link).
Ideas:
1 – Using SetPixels() with texture would most likely be easiest, just slow on bigger resolutions (but no need high resolution for this anyways?)
2 – 2D marching squares (unifywiki), but how to do falling ground..?
3 – High resolution mesh, then adjust vertices for making holes (and create extra falling mesh slices..?)
4 – 2D cellular automata thing, again its using SetPixels(), but would be nice to have 2d water on the terrain actually..
5 – Bitmap2Mesh, also using SetPixels() with texture, but could be made to use just array only..?
Idea#3: High resolution quad mesh
– Testing this first.. main screenshot is starting point (mesh, screenwidth, resolution = 1)
– Not sure yet how to handle collisions
– Making holes: Sphere(s) defines holes, all vertices inside sphere are moved down, until not inside sphere
– Collapsing: Create new mesh slices, same amount as those vertices that were moved down. Slice height = amount the vertice was moved down.. Then somehow animate them falling down.
– Weld terrain back to 1 mesh: Go trhough each slice, move the vertices below them, up to slice top Y, destroy slices.
– Problems: What is there are multiple explosions in different places..will get lots of slices on top of each other?
– Added webplayer (v1): Can destroy ground, slices are created and for now they fall with rigidbody (but wont stop), could use iTween for moving slices?
– Could probably decrease vertex count by 50%, since now each terrain slice/column is 4 vertices (not shared).
– Added webplayer (v2): Main thing missing is spherical holes from explosions..
– Added webplayer (v3):
– Spherical holes on ground using : [charp]… float angle = Mathf.Asin(counter/radius); float height = Mathf.Cos(angle)*radius; …[/charp]
– Ground plane has now half the vertices (and its smoother, since top vertices connect to previous one)
– Exploded ground slices now fall with gravity (code from http://stackoverflow.com/questions/3966188/c-sharp-xna-simulate-gravity )
– Falling slices are shown red, then after every slice has stopped, terrain vertices is set to those positions (and slices are destoyed)
—
Sources: (not finished or cleaned up..)
https://github.com/unitycoder/ScorchedEarthTerrainFail
—
Webplayer:
http://unitycoder.com/upload/demos/ScorchedEarthTerrain1/ (v1)
http://unitycoder.com/upload/demos/ScorchedEarthTerrain2/ (v2)
http://unitycoder.com/upload/demos/ScorchedEarthTerrain3/ (v3)
—
Image#2: Basic terrain shape (perlin noise), Vertices are moved down when clicking the mountain
—
Image#3: Problems if using UV maps on terrain, since if we cut part of terrain at middle, we should add more vertices there to keep UV values.. (now we have vertices only in top of the terrain and bottom, not middle). Problem creating circular holes at the moment.. Slices are now welded to main terrain after movement stops.
—
Image#4: Explosion shader (see source below) test with quad mesh primitive. Smooth edges, compared to using mesh circle. Idea is from here: Planetary rings shader
Shader "unityCoder/explocircleTest1" { Properties { _MainTex ("Base (RGB)", 2D) = "white" {} _Radius ("Radius", float) = 0.5 } SubShader { Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } LOD 200 Lighting Off CGPROGRAM #pragma surface surf Lambert sampler2D _MainTex; float _Radius; struct Input { float2 uv_MainTex; }; void surf (Input IN, inout SurfaceOutput o) { float dist = distance(IN.uv_MainTex, float2(0.5,0.5)); if ( abs(dist) > _Radius) clip (-1.0); float val = dist*128; float c1 = 1-sin(val+_Time.x)+0.5; float c2 = cos(val+_Time.y)+0.5; float c3 = 0; o.Albedo = float3(c1,c2,c3)*3; o.Alpha = 1; } ENDCG } FallBack "Diffuse" }
—
Image#5: Almost.. (see webplayer v3), but wont be able to do those small 1 pixel dirt pieces falling down like in original..not with meshes, texture with SetPixels() would be the only way i’m afraid..
Related Posts
9 Comments + Add Comment
Leave a comment
Recent posts
- [GreaseMonkey] Unity Forum Fixer
- UnityHub: Make Hub application background Translucent
- Customize SpriteShapeRenderer quality (but has issues)
- Editor tool: Copy selected gameobject’s names into clipboard as rows (for Excel)
- Editor tool: Replace string in selected gameobject’s names
- UnityHub: Enable built-in Login Dialog (no more browser login/logout issues!)
- Use TikTok-TTS in Unity (with WebRequest)
- Create Scene Thumbnail Image using OnSceneSaved & OnPreviewGUI
- webgl+javascript TTS
- Using Moonsharp (LUA) + Unity Webgl
- Using 3D gameobject prefabs with Unity Tilemap + NavMesh Surface
- Custom Unity Hub Project Template Preview Image/Video (using HTML+CSS in package description)
Recent Comments
- Vector3 maths for dummies! on
- UnityHub: Make Hub application background Translucent on
- UnityHub: Make Hub application background Translucent on
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub) on
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub) on
- [Asset Store] Point Cloud Viewer & Tools on
- [Asset Store] Point Cloud Viewer & Tools on
- ffmpeg stream raw video into Unity Texture2D on
Good work, keep it up!
Coding Destructible Pixel Terrain (with sources)
http://forum.unity3d.com/threads/198919-Destructible-Pixel-Terrain-Converting-from-Java-to-Unity-C
Random 2D terrain (with sources)
http://forum.unity3d.com/threads/199287-Random-2d-Terrain
2D Terrain Generator which used EdgeCollider2D
http://forum.unity3d.com/threads/220776-Terrain2D-Generator-Tiny-Wings-Like
Is it possible to get your source?
its quite broken still, but i’ll post soon’ish (in a week or 2)
Source is now here (its quite broken, also the game view must be some good even size, like 1024×720 or similar..otherwise it wont work)
https://github.com/unitycoder/ScorchedEarthTerrainFail
Simple destructible terrain in Unity based on bitmaps and Quadtree
https://github.com/Ideefixze/DTerrain
Destructible 2D Terrain
https://github.com/hesmeron/Destructible2DTerrain