Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Endless - 2D Terrain Generator

Discussion in 'Assets and Asset Store' started by NeilMeredith, Oct 25, 2013.

  1. awardell

    awardell

    Joined:
    Feb 5, 2014
    Posts:
    71
    Figured out what the issue was! When the piece is being constructed, it only becomes relative to the last generated mesh piece AFTER it's finished generating and is moved there. The key vertices, when they're being constructed, are in absolute space. All I had to do, in addition to what I was already doing, was to add this little snip of code in GenerateKeyVertices:
    Code (csharp):
    1.  
    2. if (CurrentTerrainRule.SelectedTerrainStyle == TerrainRule.TerrainStyle.Random)
    3.                 {
    4.                     float y = GetKeyVertexRandomHeight();
    5.                    
    6.                     if (limitRandom)
    7.                     {
    8.                         if (verticies.Count == 0)
    9.                         {
    10.                             y = 0;
    11.                         }
    12.                         else
    13.                         {
    14.                             y += verticies.Last().y;
    15.                         }
    16.                     }
    17.                    
    18.                     float x = CurrentLocation + keyVertexStepSize;
    19.                     Vector3 vertex = new Vector3(x, y, settings.OriginalStartPoint.z);
    20.                     NextOrigin = NextOrigin + vertex;
    21.                     verticies.Add(vertex);
    22.                     Debug.Log(vertex);
    23.                 }
    24.  
     
  2. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    Wait...wait....so were those other snippets actual changes? I thought you were just posting original code from the asset....
    Is your final solution to make it so that the min and max terrain height work in absolute instead of relative terms?
    (thanks in advance for your efforts!!!)
     
  3. awardell

    awardell

    Joined:
    Feb 5, 2014
    Posts:
    71
    Those were actual changes that I made. And it doesn't replace the min and max that were there, but it's in addition to that. The old min/max are still there to determine how high a hill can be and how low a valley can be, but now it's bounded by the absolute min/max as well. The only change I made which I didn't post in a snippet was replacing my stub values with values from new entries I added to the editor.
     
  4. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    perfect...thanks again.
    Is it working out for you? (after implementation and experimentation)
     
  5. awardell

    awardell

    Joined:
    Feb 5, 2014
    Posts:
    71
    Yeah, my solution is working for me. It's not the most robust or well-integrated, but the terrain generator is quite a beast to tamper with.
     
  6. ImpossibleRobert

    ImpossibleRobert

    Joined:
    Oct 10, 2013
    Posts:
    511
    A pattern that I unfortunately see happen very often on the asset store is that someone will release a first version and then never improves that again. Looking at the release history, the feature requests here and that it's virtually been forever that any update came let me ask bluntly so that we at least all know what we as customers are up to and can find a solution ourselves:

    Will the Terrain Generator still be improved significantly in the future or is the maximum we can expect minor bug fixes?

    I really hope it's the first one since this project has so much awesome potential.
     
  7. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333

    The author clearly stated 3 weeks ago on this thread: "I do plan another release at some point in the future, but it will mostly be minor tweaks and fixes, I have no major new features planned"
    He HAS put out several versions/bug fixes since his original release.
    I dunno...I have been on the receiving end of a LOT of Unity assets - this one actually strikes me as a rare shining star

    #1 He has a free trial version of the asset - RARE in the non-art asset space. If it doesn't want what you want, you can find out without spending money.
    #2 He includes source code which is not required and is often not done. This has allowed me (and others) to extend and tweak the asset as we need - and this forum allows us to pass that info around to each other
    #3 The code is EXTREMELY well written and commented.

    While I would LOVE to see the author continue to slave away for me for the next year to fully 'earn' the $30 I paid him (sarcastic), I am happy with my purchase overall.
    @10FingerAmy - I'm not bashing you - just putting a more positive spin on things.
     
  8. NeilMeredith

    NeilMeredith

    Joined:
    Jul 15, 2013
    Posts:
    81
    @awardell - Great, I'm glad you were able to get this working the way you need!

    @10FingerArmy - I wrote this asset as a way of learning unity, and although directly generating the terrain meshes is the most flexible approach, if I were writing it all over again I'd probably use pre-made prefabs and string them together with set rules. I think this would give more customization options, without the complexity of the generated meshes.

    Given that I am not sure this is the most easily maintainable approach for a terrain generator, I don't plan any major updates to this asset. I understand that is disappointing, and I did originally plan some more changes, but given the time required vs. the sales of the asset, it just isn't worth it to me at this time.

    @casperjeff - Thanks for the support, and as always I am glad to hear that you have been able to customize this to work how you need it to.
     
  9. ImpossibleRobert

    ImpossibleRobert

    Joined:
    Oct 10, 2013
    Posts:
    511
    @Neil: Please don't mistake my inquiry for an assault or even insult. I am just a big fan of transparency. Especially when we as customers rely on third party assets for central functionality. For many this is a hobby but for others this can also be very business critical. I am working with lots of open source in my day job for a huge software company and I am quite often faced with such scenarios. Basically the learning is that as soon as a project is being put into maintenance/abandon mode it will most often gradually die.

    I am very passionate about what you created here and I am super thankful for that. You did a great job and I see so many directions this could evolve to. Also the timing was perfect for me as I was actually planning to build something like that myself. I also thank your for being very open at this point in time. I now know that we have to plan implementation time for future improvements which is unfortunate but still ok. It gets us out of uncertainty and waiting mode.

    Maybe we can get a little community together to develop it further. What do the others here think? Do any features I requested in earlier posts (the ones with the bold headlines) resound with others?
     
  10. NeilMeredith

    NeilMeredith

    Joined:
    Jul 15, 2013
    Posts:
    81
    @10FingerArmy - I don't take it as an attack, I understand that you just need to know where the asset is going, so I wanted to be upfront about that. I think the idea of a community to develop it further is a great idea, and I hope you and others who have been working with the asset can enhance it further.
     
  11. ImpossibleRobert

    ImpossibleRobert

    Joined:
    Oct 10, 2013
    Posts:
    511
    @Neil: I have a rather radical proposition and would like to know your opinion: If we look at what UMA did they created a public github repository for their source and everybody who feels qualified can contribute. I have several patches in mind which I would instantly contribute. Others would probably also consolidate their changes there. Is this something that would resonate with you? It of course depends also on what asset store income you generate but I read between the lines that it must be not what you rightfully hoped for. I think for adoption this could be one of the best options and it might actually be a nice reference for you if it should actually get some traction through this channel. People love free stuff :)
     
  12. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    oooo...."this" close to having tunnels........
    (really just 2 endless terrain components on same scene).
    Working on inverting things properly so prefabs are instantiated the right way (or at least the way I want them)
    note the extra 'instanceID' attached to the terrain/prefab managers - that was to deal with the nifty way the author instantiated his manager gameobjects.

    SOOOOO excited.

    $1.jpg
     
    Last edited: Apr 8, 2014
  13. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    Less excited.
    Because of the order of instantiation - REALLY hard to grab inverted scale data from upper levels using parent/child stuff -
    Looks like I will have to add a new setting for 'inversion' and work from there.
    *grumble*.

    Still excited though about the possibility!!!!

    http://upload.wikimedia.org/wikipedia/en/b/bc/Scramble.gif
     
  14. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    Success!! I HAVE TUNNELS!!
    2 endless terrains - 1 inverted - with prefabs showing in correct place.

    I'll take some time tonight to put some snippets together to show others how to do.

    $1.jpg
     
    Last edited: Apr 9, 2014
  15. ImpossibleRobert

    ImpossibleRobert

    Joined:
    Oct 10, 2013
    Posts:
    511
    @jeff: how do you ensure that the tunnels don't converge or diverge but instead stay in a defined vertical range. With the current implementation it can happen easily that the terrain goes only up or downwards since it is random. So if the lower terrain only goes upwards and the upper one only downwards they will meet and intersect at some point, don't they?
     
  16. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    I'm fine-tuning solution that @awardell suggested (above) to avoid the terrain height creep.....(I think he has a flaw in that if the terrain tries to go below the threshhold, it will simply stay at same level - and ends up leaving unintended non-random looking flat spots)

    So as long as I start the top and bottom terrains far enough apart and I give them good 'absolute' Y min/maxes, I will be good to go!
     
  17. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    yeah---been playing with this....it certainly works as advertised....thanks SO much for your efforts
    (Not 100% sure what the "limitRandom" is for in VertexGenerator - but I created it and set value to true to get things to work properly.
    My head starts hurting when I try to hack on this code too much...)

    Now to merge this with my 'flat places' logic, add in logic to prevent overlapping prefabs and I am off to the races!!!
     
  18. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    oooooooo.....
    $1.jpg
     
  19. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333

    @awardell - quick question. What do minStub and maxStub represent here? Are they upper and lower boundaries in absolute position? relative from terrain origin position? While I can get this technique to work if I tweak the starting terrain position, min/max height and these values for a while, I feel like I am throwing darts at a dartboard...
     
  20. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    @NeilMeredith

    Some issues when running under IOS (7.1) via XCode 5.1)
    Code (csharp):
    1.  
    2. Rethrow as TypeInitializationException: An exception was thrown by the type initializer for PredicateOf`1
    3.   at Endless2DTerrain.VertexGenerator.GenerateKeyVerticies (Boolean updateRepeatingPointLocation) [0x00000] in <filename unknown>:0
    4.   at Endless2DTerrain.MeshPiece.PopulateKeyVerticies (Plane planeType) [0x00000] in <filename unknown>:0
    5.   at Endless2DTerrain.TerrainPiece.Create (Endless2DTerrain.VertexGenerator vg, Vector3 origin) [0x00000] in <filename unknown>:0
    6.   at Endless2DTerrain.TerrainManager.GenerateTerrainPiece (Endless2DTerrain.TerrainPiece currentTerrain, Vector3 origin) [0x00000] in <filename unknown>:0
    7.   at Endless2DTerrain.TerrainManager.Generate (Single endX) [0x00000] in <filename unknown>:0
    8.   at TerrainDisplayer.GenerateTerrain (Single leadAmount) [0x00000] in <filename unknown>:0
    9.   at TerrainDisplayer+<GenerateTerrainCoroutine>c__Iterator1.MoveNext () [0x00000] in <filename unknown>:0
    10. UnityEngine.MonoBehaviour:StartCoroutine_Auto(IEnumerator)
    11. UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
    12. TerrainDisplayer:Update()
    13.  
    Looks like your LINQ stuff is not liked by the runtime stuff on IOS (at least in all cases).
    I think I can replace your two '.Last()' calls in GenerateKeyVerticies() easy enough but the " float minY = topVerticies.Select(t => t.y).Min();" reference in GenerateFlatLowerBoundVerticies() might be trickier.
    Any thoughts?
     
  21. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333

    I removed your linq references by implementing a couple of replacement functions
    Code (csharp):
    1.  
    2. private float MyMinimum(List<Vector3> myList){
    3.             float retval = 1000000000f;
    4.             foreach(Vector3 myVector in myList){
    5.                 if(myVector.y < retval){
    6.                     retval = myVector.y;
    7.                 }
    8.             }
    9.             return retval;
    10.         }
    11.  
    12.         private Vector3 MyLast(List<Vector3> myList){
    13.             if (myList != null)
    14.             {
    15.                 int count = myList.Count;
    16.                 if (count > 0)
    17.                 {
    18.                     return myList[count - 1];
    19.                 }
    20.             }
    21.             return Vector3.zero;
    22.         }
    23.  
    Kind of hackish - and I'm sure there is a more elegant solution, but there you go.
    Works on my IOS7.2 iPad now....
     
  22. justeenm_bgi

    justeenm_bgi

    Joined:
    Feb 25, 2014
    Posts:
    1
    Hi Neil,

    We just bought your plugin and it's working real great, i just wanna ask, is it possible to modify the terrain rules dynamically? thanks in advance! :D
     
  23. NeilMeredith

    NeilMeredith

    Joined:
    Jul 15, 2013
    Posts:
    81
    Justeenm_bgi,

    I've been gone on vacation without internet access for the past week, sorry for the slow reply. I suppose you could modify the rules dynamically...they are all setup and added to the Settings object that gets passed around through the code. If you adjusted the Rules or PrefabRules list there, then they should get picked up when the next bit of terrain gets generated.

    -Neil

    Code (csharp):
    1.  
    2.     public void Setup()
    3.     {
    4.         if (Rules != null)
    5.         {
    6.             Settings s = new Settings();
    7.             s.Rules = Rules;
    8.             s.PrefabRules = PrefabRules;
    9.             s.MainMaterial = MainMaterial;
    10.             s.MainMaterialXTiling = MainMaterialXTiling;
    11.             s.MainMaterialYTiling = MainMaterialYTiling;
    12.             s.MainMaterialRotation = MainMaterialRotation;
    13.             //etc...
    14.        }
    15.  
    16. }
    17.  
     
  24. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    (related to the IOS runtime error)
    Yeah...it might have been the changes that I implemented that @awardell suggested for limiting height meandering...sorry for the noise.
     
  25. kulesz

    kulesz

    Joined:
    Jul 1, 2012
    Posts:
    137
    Is there any workaround known for the lack of Unity 2D Physics support?
    I bought this asset and I'm a bit disappointed, that it is not using this new features.
     
  26. NeilMeredith

    NeilMeredith

    Joined:
    Jul 15, 2013
    Posts:
    81
    @kulesz

    A previous customer modified this to use the new 2d physics (it was originally written before that came out) and said the changes were fairly simple. I think he sent some sample code too...I'll dig through my email and see if I can find it.

    -Neil
     
  27. Squashuux

    Squashuux

    Joined:
    Apr 17, 2014
    Posts:
    2
    When I play the demo scenes the koala sprite runs on the terrain for about a second before shrinking while falling through the terrain then disappearing. When I go to the sprite's character controller while the game is running and do not place a value in min move distance field the scene runs normally but when I retype the 0 in that field the above problem happens. I have not modified anything. What could be the problem?
     
  28. kulesz

    kulesz

    Joined:
    Jul 1, 2012
    Posts:
    137
    Thanks you, I'll wait for your support :)
    BTW. Soon we're releasing game which is using your addon :)
     
  29. NeilMeredith

    NeilMeredith

    Joined:
    Jul 15, 2013
    Posts:
    81
    @squashuux - I'm not sure what might be happening in your case, I haven't had any other reports of issues with the demo scenes. What version of Unity are you using, and are you running on a mac or a pc?

    @kulez- These changes are courtesy of Ronan, who made the updates in his own project and sent them to me. I haven't tried them, but they worked for him. He modified the AddCollider function in the MeshPiece class, and added the helper function below it. He also added the Use2DCollider toggle to the settings class and in the custom inspector.

    Code (csharp):
    1.  
    2. public void AddCollider()
    3.         {
    4.             if (PlaneType == Plane.Top  settings.DrawTopMeshCollider)
    5.             {
    6.                 if (settings.Use2DCollider) {
    7.                     polygonCollider.pathCount = 1;
    8.                     polygonCollider.SetPath(0, Get2DColliderVerts(mesh.vertices));
    9.                 }
    10.                 else {
    11.                     var colliderMesh = new Mesh();
    12.                     colliderMesh.vertices = mesh.vertices;
    13.                     colliderMesh.triangles = mesh.triangles;
    14.                     colliderMesh.RecalculateBounds();
    15.  
    16.                     meshCollider.sharedMesh = colliderMesh;
    17.                     meshCollider.smoothSphereCollisions = true;
    18.                 }
    19.             }
    20.         }
    21.  
    22.         Vector2[] Get2DColliderVerts(Vector3[] meshVertices) {
    23.             List<Vector2> verts = new List<Vector2>();
    24.  
    25.             // Convert vertices to Vector2 coords, and remove duplicates
    26.             foreach(Vector3 meshVert in meshVertices) {
    27.                 verts.Add(new Vector2(meshVert.x, meshVert.y));
    28.             }
    29.  
    30.             // Add bottom verts
    31.             for (int i = (verts.Count - 1); i >= 0; i--) {
    32.                 verts.Add(new Vector2(verts[i].x, verts[i].y - 1f));
    33.             }
    34.  
    35.             return verts.ToArray();
    36.         }
    37.  
    38.  
     
  30. Squashuux

    Squashuux

    Joined:
    Apr 17, 2014
    Posts:
    2
    I am on PC and am using the latest version of Unity.
     
  31. awardell

    awardell

    Joined:
    Feb 5, 2014
    Posts:
    71
    Hey Neil,

    I'd like to make a complaint/suggestion about the Terrain Generator. Currently, having lots of prefab rules can be very difficult to manage. They can't be ordered, can't be copied except for the last one, and certainly can't be copied between separate terrain generators. It would be great if prefab rules were actually components which could be attached to the generator. Then when the generator runs, it could poll for the rules that are attached to it. The same could be done with terrain rules. This would make the generator so much nicer to work with. I want to do it myself, but don't know if I'll have the time to. But if I do I'll share it here.
     
  32. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    Yeah...I ended up creating terrain and prefab rules in code.
    Was much easier when you have a lot of them...

    Code (csharp):
    1.  
    2.    public void Setup()
    3.     {
    4.         if (Rules != null)
    5.         {
    6.             Settings s = new Settings();
    7.              ...
    8.             List<TerrainRule> DynamicRules = DynamicTerrainRuleManager.GenerateDynamicTerrainRules();
    9.             s.Rules = DynamicRules==null?Rules:DynamicRules;
    10.  
    Code (csharp):
    1.     public class DynamicTerrainRuleManager
    2.         {
    3.             static TerrainRule[] fixedRules = new TerrainRule[] {
    4.             new TerrainRule (TerrainRule.TerrainStyle.Random, TerrainRule.TerrainLength.Fixed, TerrainRule.TerrainPurpose.Transition, -20f, 20f, 40f, 30f, 5f, 3000f, 1000f, 0f, "", false, 10f, 3f, "Start"),
    5.             new TerrainRule (TerrainRule.TerrainStyle.Random, TerrainRule.TerrainLength.Fixed, TerrainRule.TerrainPurpose.Transition, -20f, 20f, 40f, 30f, 5f, 4000f, 1000f, 0f, "SparseBuildings", true, 10f, 3f, ""),
    6.             new TerrainRule (TerrainRule.TerrainStyle.Random, TerrainRule.TerrainLength.Fixed, TerrainRule.TerrainPurpose.Action, -20f, 20f, 40f, 30f, 5f, 8000f, 1000f, 0f, "SparseBuildings,FallingAsteroids,Shuttle,Powerups", true, 10f, 6f, "Rocks From The Sky?"),
    7.             new TerrainRule (TerrainRule.TerrainStyle.Random, TerrainRule.TerrainLength.Fixed, TerrainRule.TerrainPurpose.Transition, -20f, 20f, 40f, 30f, 5f, 2400f, 1000f, 0f, "SparseBuildings,Powerups", true, 10f, 4f, ""),
    8.             new TerrainRule (TerrainRule.TerrainStyle.Random, TerrainRule.TerrainLength.Fixed, TerrainRule.TerrainPurpose.Action, -20f, 20f, 40f, 30f, 5f, 8000f, 1000f, 0f, "SparseBuildings,HorizontalRockets,Powerups,Shuttle", true, 10f, 6f, "Rockets From the Right"),
    9.             new TerrainRule (TerrainRule.TerrainStyle.Random, TerrainRule.TerrainLength.Fixed, TerrainRule.TerrainPurpose.Transition, -20f, 20f, 40f, 30f, 5f, 2400f, 1000f, 0f, "SparseBuildings,Powerups", true, 10f, 4f, ""),
    10.             new TerrainRule (TerrainRule.TerrainStyle.Random, TerrainRule.TerrainLength.Fixed, TerrainRule.TerrainPurpose.Action, -20f, 20f, 40f, 30f, 5f, 8000f, 1000f, 0f, "SparseBuildings,AtomicBomb,Powerups,Shuttle", true, 10f, 6f, "What New Hell Is This?"),
    11.             new TerrainRule (TerrainRule.TerrainStyle.Random, TerrainRule.TerrainLength.Fixed, TerrainRule.TerrainPurpose.Transition, -20f, 20f, 40f, 30f, 5f, 2400f, 1000f, 0f, "SparseBuildings,Powerups", true, 10f, 4f, ""),
    12.             new TerrainRule (TerrainRule.TerrainStyle.Random, TerrainRule.TerrainLength.Fixed, TerrainRule.TerrainPurpose.Action, -20f, 20f, 40f, 30f, 5f, 8000f, 1000f, 0f, "TightBuildings,HorizontalRockets,AtomBomb,Powerups,Shuttle", true, 6f, 6f, " All Out Urban Assault"),
    13.             new TerrainRule (TerrainRule.TerrainStyle.Random, TerrainRule.TerrainLength.Fixed, TerrainRule.TerrainPurpose.Transition, -20f, 20f, 40f, 30f, 5f, 2400f, 1000f, 0f, "SparseBuildings,Powerups", true, 10f, 4f, ""),
    14.             new TerrainRule (TerrainRule.TerrainStyle.Random, TerrainRule.TerrainLength.Fixed, TerrainRule.TerrainPurpose.Action, -20f, 20f, 40f, 30f, 5f, 8000f, 1000f, 0f, "TightBuildings,HorizontalRockets,AtomBomb,FallingAsteroids,Shuttle,Powerups", true, 6f, 6f, "Armageddon!!"),
    15. };
    16.             public static  List<TerrainRule> GenerateDynamicTerrainRules ()
    17.             {
    18.                         return  new List<TerrainRule> (fixedRules);
    19.             }
    20.  
    21.         }
    I also gave my prefab rules 'names' so that I could reference them in code easier and better know what I was putting where
     
  33. kulesz

    kulesz

    Joined:
    Jul 1, 2012
    Posts:
    137
    @NeilMeredith

    Thank you very much - I applied changes that you proposed and everything works fine. It took me less than 20 minutes to get everything done.
    I think you should add it to the official version, as 2D Physics will be probably more and more used (and supported by Unity). It could add serious value to your product :)
    Cheers.
     
  34. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    @NeilMeredith
    Question - it appears to me that you are iterating through each prefab rule on every top vertices - and then checking logic for spacing/grouping/etc...
    Shouldn't you be short-circuiting on ones that aren't 'allowed' for that prefab?

    Code (csharp):
    1.     for (int i = 0; i < terrainManager.AllFrontTopVerticies.Count(); i++)
    2.             {
    3.                 Vector3 current = terrainManager.AllFrontTopVerticies[i];
    4.  
    5.                 for (int j = 0; j < settings.PrefabRules.Count(); j++)
    6.                 {

    In keeping with that thought - I tried to move that logic up a bit to make it less 'costly' for each terrain generation and things went floopy (pre-fabs started instantiating right in the middle of current terrain section I was traveling on)

    I am obviously missing something - any thoughts as to the why/how of this?
     
  35. miacoviello

    miacoviello

    Joined:
    Apr 29, 2013
    Posts:
    6
    Hi,
    the koala in the sample scene just falls through the terrain. This asset looks great, but I cant seem to get past it. There have been no changes made to the scenes and they all have the same issue (koala just falls), Unity 4.3.4f1 professional. Please let me know the issue.

    Michael Iacoviello
     
  36. NeilMeredith

    NeilMeredith

    Joined:
    Jul 15, 2013
    Posts:
    81
    @miacoviello,

    Michael...I just can't replicate this. I'm not sure why it is happening for you, but if you can't get it to work send me your invoice number and I will refund your purchase.

    -Neil
     
  37. miacoviello

    miacoviello

    Joined:
    Apr 29, 2013
    Posts:
    6
    Hi Neil, thanks for responding - I worked it out. I imported into an existing project that was started as a "2d" project. Seems this issue does not occur when the project type is started as "3d". Hopefully this will help others as well - I know there is patched code above in the thread we can use to go with the 2d project, but is there any expectation of true support for this project type?
     
  38. NeilMeredith

    NeilMeredith

    Joined:
    Jul 15, 2013
    Posts:
    81
    I will no longer be able to offer support for this asset, but decided to make it free and hope the source code is useful to anyone wanting to do something similar. Enjoy!
     
  39. ShinyTaco

    ShinyTaco

    Joined:
    Sep 4, 2012
    Posts:
    70
    Hello, really love this and thanks for making it free.

    How can we make the width of the terrain wider?

    Thanks!

    *Edit*

    Nevermind, I see that it's called Height also, but for the top. I was looking for width. Thanks, love this Asset. Great work!
     
    Last edited: Jun 23, 2014
  40. bizilux1

    bizilux1

    Joined:
    Jun 6, 2013
    Posts:
    151
    thank you for making this plugin free!!!

    now i do realize you made it for free because you dont have time to support it, so im hoping some other member on here will help me with this ridicilously easy question.

    i want to add 2D colliders to terrain, and i followed this guide

    and it doesnt work for me, i dont know how to code, so this is the problem... can anyone describe it to me a bit on what i have to do?


    1. He modified the AddCollider function in the MeshPiece class
    2. added the helper function below it.
    3. He also added the Use2DCollider toggle to the settings class and in the custom inspector.

    I only completed first step. i do not know how to complete second and third. please help :)


     
  41. awardell

    awardell

    Joined:
    Feb 5, 2014
    Posts:
    71
    Hey Neil,

    Since you've made this asset free and open-source, how would you feel about getting it into an open-source repo on github? There are lots of improvements that can be made to the codebase, and with an open repository people could submit those improvements and it could continue to be useful without direct support from you.
     
  42. NeilMeredith

    NeilMeredith

    Joined:
    Jul 15, 2013
    Posts:
    81
    Awardell,

    I'm totally ok with that. I use mercurial and not git, so I don't have everything installed I need to get this up on github. I'll get around to it at some point, but if you want to put it up on github and just link back to the asset and this thread, that would be fine too.
     
  43. x8105

    x8105

    Joined:
    Apr 4, 2011
    Posts:
    5
    What's the status on this one, I am really loving this asset.
     
  44. MagnusAshish

    MagnusAshish

    Joined:
    Dec 16, 2013
    Posts:
    3
    I request everyone who has spare time to provide a tutorial about how to use this asset with the new 2d tools so that
    it can collide 2d sprites. It will be great for people like me who are new to coding to take advantage of this great asset.
     
  45. x8105

    x8105

    Joined:
    Apr 4, 2011
    Posts:
    5
    poke poke is this thing still on?
     
  46. shopguy

    shopguy

    Joined:
    Jan 12, 2013
    Posts:
    282
    Edit: I ended up having to make a lot more changes than listed below, too extensive to list in this format... I'll try to post a ZIP file somewhere once I'm done with all of the modifications for 2D colliders, although I'm guessing someone has already done this on github or something and I just haven't found it.

    Step 1 and 2 code (Replace current AddCollider in MeshPiece.cs and add this 2nd function):

    Code (CSharp):
    1.         public void AddCollider()
    2.         {
    3.             if (PlaneType == Plane.Top && settings.DrawTopMeshCollider)
    4.             {
    5.                 if (settings.Use2DCollider)
    6.                 {
    7.                     polygonCollider.pathCount = 1;
    8.                     polygonCollider.SetPath(0, Get2DColliderVerts(mesh.vertices));
    9.                 }
    10.                 else
    11.                 {
    12.                     var colliderMesh = new Mesh();
    13.                     colliderMesh.vertices = mesh.vertices;
    14.                     colliderMesh.triangles = mesh.triangles;
    15.                     colliderMesh.RecalculateBounds();
    16.  
    17.                     meshCollider.sharedMesh = colliderMesh;
    18.                     meshCollider.smoothSphereCollisions = true;
    19.                 }
    20.             }
    21.         }
    22.  
    23.         Vector2[] Get2DColliderVerts(Vector3[] meshVertices)
    24.         {
    25.             List<Vector2> verts = new List<Vector2>();
    26.          
    27.             // Convert vertices to Vector2 coords, and remove duplicates
    28.             foreach (Vector3 meshVert in meshVertices)
    29.             {
    30.                 verts.Add(new Vector2(meshVert.x, meshVert.y));
    31.             }
    32.      
    33.             // Add bottom verts
    34.             for (int i = (verts.Count - 1); i >= 0; i--)
    35.             {
    36.                 verts.Add(new Vector2(verts[i].x, verts[i].y - 1f));
    37.             }
    38.             return verts.ToArray();
    39.         }
    40.  
    Also I added the polygonCollider line to this part of code at the top of MeshPiece.cs:

    Code (CSharp):
    1.         //Reference to the components we need to build our mesh
    2.         private MeshFilter meshFilter { get; set; }
    3.         private MeshRenderer meshRenderer { get; set; }
    4.         private MeshCollider meshCollider { get; set; }
    5.         private PolygonCollider2D polygonCollider { get; set; }
    6.         public Mesh mesh { get; set; }
    7.  
    Step 3 code, Settings.cs, down towards the bottom I added the Use2DCollider line below terrainDisplayer:

    Code (CSharp):
    1.         public TerrainDisplayer terrainDisplayer { get; set; }
    2.  
    3.         public bool Use2DCollider { get; set; }
    4.  
    Edit: Also had to update TerrainDisplayer.cs. Added Use2DCollider lines in 2 places:

    Towards top of file:

    Code (CSharp):
    1.     //Top plane settings
    2.     public Material TopMaterial;
    3.     public float TopMaterialXTiling;
    4.     public float TopMaterialYTiling;
    5.     public float TopMaterialRotation;
    6.     public bool DrawTopMeshCollider;
    7.     public bool Use2DCollider;
    8.     public bool DrawTopMeshRenderer;
    9.     public float TopPlaneHeight;
    10.  
    In the Setp() function:

    Code (CSharp):
    1.             s.DrawTopMeshCollider = DrawTopMeshCollider;
    2.             s.Use2DCollider = Use2DCollider;
    3.  
     
    Last edited: Nov 2, 2014
  47. shopguy

    shopguy

    Joined:
    Jan 12, 2013
    Posts:
    282
    If anyone has modified the code to use EdgeCollider2D instead of PolygonCollider2D, I'd love to see that. I'm probably going to do it myself if not, but not sure if I'll have time or not. If I do, I'll post my updates on this thread, or if I make enough other changes I might just post a modified version of the entire package/source somewhere. I don't use github or any of those types of tools, so will not be something like that, just a ZIP file somewhere probably.
     
  48. shopguy

    shopguy

    Joined:
    Jan 12, 2013
    Posts:
    282
    Couldn't figure out how to attach files here (maybe not possible), so just uploaded to my company web server. If anyone wants to upload to a better public location or these forums, that would be great (in case my company website goes offline when we go bankrupt like most game devs, lol).

    http://braincrook.com/2DTerrainGenMod.zip

    The above ZIP file includes mods to have a EdgeCollider2D instead of MeshCollider. I also disabled the extra colliders on the other 2 mesh pieces, since for my needs (and I think most) you just need 1 edge collider on top. Would be cool if someone makes a version that supports an edge collider on the bottom and also having the top edge (the green grass part in demos) be on the bottom... but I don't need that for my current project so not something I'll be working on soon.

    Edit: I also created this version which is really stripped down and optimized for 2D only. It only creates 2 meshes (Detail and Front), not the "Top" mesh... well, just try it if you only care about 2D, it creates less components, just the ones you really need for 2D. I don't have any sample scenes or anything to share, sorry, this is just the contents of the Script folder modified for my needs.

    http://braincrook.com/2DTerrainGenMod2.zip
     
    Last edited: Nov 2, 2014
    MD_Reptile likes this.
  49. Tvashta-Games

    Tvashta-Games

    Joined:
    Nov 1, 2014
    Posts:
    1
    I created a simple "Endless 2D Terrain" using this great asset and it works great on PC but when I try to run it as a Windows Store App; new terrain is not generated beyond "Preview Length" and it gives the following error:


    Code (csharp):
    1. A first chance exception of type 'System.Exception' occurred in Assembly-CSharp.DLL
    2. An exception of type 'System.Exception' occurred in Assembly-CSharp.DLL but was not handled in user code
    3. Additional information: Terrain rules required to generate vertices
    4.  
    5. Exception: Terrain rules required to generate vertices
    6. Type: System.Exception
    7. Module: Assembly-CSharp
    8. InnerException: <No Data>
    9. AdditionalInfo:<No Data>
    10.    at Endless2DTerrain.VertexGenerator..ctor(Settings s)
    11.    at Endless2DTerrain.TerrainManager..ctor(Settings s)
    12.    at TerrainDisplayer.Setup()
    13.    at TerrainDisplayer.Awake()
    14.    at TerrainDisplayer.$Invoke0(Int64 instance, Int64* args)
    15.    at UnityEngine.Internal.$MethodUtility.InvokeMethod(Int64 instance, Int64* args, IntPtr method)
    16.  
    17. (Filename: C:/buildslave/unity/build/Runtime/Scripting/WinRTUtility.cpp Line: 87)
    18.  
    19.  
    20. The thread 0xdb0 has exited with code 0 (0x0).
    21. Exception: Terrain rules required to generate vertices
    22.    at Endless2DTerrain.VertexGenerator..ctor(Settings s)
    23.    at Endless2DTerrain.TerrainManager..ctor(Settings s)
    24.    at TerrainDisplayer.Setup()
    25.    at TerrainDisplayer.Awake()
    26.    at TerrainDisplayer.$Invoke0(Int64 instance, Int64* args)
    27.    at UnityEngine.Internal.$MethodUtility.InvokeMethod(Int64 instance, Int64* args, IntPtr method)
    28. (Filename: TODO Line: 0)
    29.  


    I don't know much about coding so I can't figure out what's wrong. Please help me on this.
     
    Last edited: Nov 6, 2014
  50. aegodbold

    aegodbold

    Joined:
    Aug 24, 2013
    Posts:
    3
    Shopguy, you're awesome!