Search Unity

Endless - 2D Terrain Generator

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

  1. diegoadrada

    diegoadrada

    Joined:
    Nov 27, 2014
    Posts:
    59
    Hello, first of all, thank you very much for this tool, it is actually very useful. I'm using for a 2D runner, according to the modifications made by "shopguy" all that works well.
    My problem is that I'm trying to detect when my character is touching the ground, so far I've done using Linecast with a Layer called Ground and had worked very well.
    Now that does not work and does not detect when the character is on the ground, I would like to know if you have any suggestions.
    I think that i need is that the "MeshPiece" which contains the collider, it will automatically create with "Ground" label.
    Thank you very much!

    Edit:
    I've been able to solve, I created another function called "AddTag" to which I call when MeshObject is instantiated.
    Code (CSharp):
    1.         private void InstantiateMeshObject()
    2.         {
    3.             MeshObject = new GameObject("MeshPiece");
    4.             AddMeshComponents();
    5.             AddTag ();
    6.  
    7.         }
    8.         private void AddTag()
    9.         {
    10.             // 8 corresponds to Layer "Ground"      
    11.             MeshObject.layer = 8;
    12.         }
     
    Last edited: Nov 27, 2014
  2. shopguy

    shopguy

    Joined:
    Jan 12, 2013
    Posts:
    282
    Thanks aegodbold, glad it helped someone. I don't think I'll be making any other updates as I ended up just buying Ferr2D off the asset store and it has saved me lots of time and does everything I need so far.
     
  3. eridani

    eridani

    Joined:
    Aug 30, 2012
    Posts:
    655
    Ferr2D can be used to make endless terrain? That would be neat... I thought it was just a level layout tool.
     
  4. IndusGeek

    IndusGeek

    Joined:
    May 21, 2014
    Posts:
    34
    hello,

    the terrain generator, has been very useful for the current game i am working on. and its amazing.
    i got the terrain working in no time and also my character runs on the terrain very well.

    though i was trying to generate a similar terrain with different randomness and which would be running at the background with a slower speed with respect to the main terrain in front. (similar to Ski Safari..background)

    Any Suggestions for it Please.
     
  5. shopguy

    shopguy

    Joined:
    Jan 12, 2013
    Posts:
    282
    No, not really designed for endless. In my case I didn't actually need endless, just "pretty long".
     
    eridani likes this.
  6. diegoadrada

    diegoadrada

    Joined:
    Nov 27, 2014
    Posts:
    59
    Has anyone else done this? It's just what I need, but I sent a PM to casperjeff and have not yet received a response. If someone has done this too, I would be of great help. Likewise I will try to make that change, if I succeed, I'll post the solution here.
     
    Sniper30morgh likes this.
  7. SATANA666

    SATANA666

    Joined:
    Jul 31, 2013
    Posts:
    1
    Hi, this asset is awesome!
    Tell me please, how can I restrict lower or/and upper Y coordinate (in world space) of the terrain surface? For example I have several different rules with different height and length and I need the terrain surface location never falls below 0, but I don't know how to implement that. Do anyone have any suggestions?
     
    Last edited: Dec 14, 2014
  8. Cocanuss

    Cocanuss

    Joined:
    Dec 19, 2014
    Posts:
    1
    Hi - very nice asset!

    What am I doing wrong, I have a simple sprite (my player) with rigidbody 2d and circle Collider 2d. Now I added a terrain to my scene, but it doesnt collide with my player... what have I missed?

    Thanks
     
  9. ANTARES_XXI

    ANTARES_XXI

    Joined:
    Dec 23, 2014
    Posts:
    141
    Well, I have almost same problem. And the asset is really nice!
     
  10. da_st

    da_st

    Joined:
    Nov 21, 2014
    Posts:
    259
    Hello

    I find this asset very useful, but im wondering if there is any way to make the prefabs spawn "randomly", because at the moment they are spawning at the same distance over and over, making them very predictable for the player.

    I have tried setting the min and max repeat distance but they still are not "randomly" appearing, if anyone knows how to fix this i would really appreciate it! :)
     
  11. DevMerlin

    DevMerlin

    Joined:
    Dec 21, 2011
    Posts:
    96
    The asset was published before the 2D collision options came out I believe, I think you'll have to use a 3D collider if you want this.
     
  12. DevMerlin

    DevMerlin

    Joined:
    Dec 21, 2011
    Posts:
    96
    I don't know if this is the best place to mention it, but I'm making several small modifications to the asset itself, including it's editor functions. I know the author said it was now free and to expand on it if we had to. Once I figured out how, I started adding in some features - Randomization (complete with use greater or less than) and defining the randomization rule for a prefab to appear, and now a Distance to Appear at - which could be useful for a goal. They seem to be working, although the Distance to Appear At is dependent on a value I provided. However, it ought to be easily changeable. Would it be okay or should I make these edits available?
     
  13. ANTARES_XXI

    ANTARES_XXI

    Joined:
    Dec 23, 2014
    Posts:
    141
    It would be great if you'd share the "Distance to Appear At" feature!
     
  14. da_st

    da_st

    Joined:
    Nov 21, 2014
    Posts:
    259
    Hey it would be nice if you could share us the randomization for prefabs function! :)
     
  15. DevMerlin

    DevMerlin

    Joined:
    Dec 21, 2011
    Posts:
    96
    Okay, I'll keep working on it and then post once I'm satisfied - hopefully by the weekend of 1/13. I can't guarantee that my edits will be as good as the author's - I'm still studying how various little functions within this work.
     
  16. greenrift

    greenrift

    Joined:
    Jun 25, 2014
    Posts:
    6
    I may have missed it in the discussion here and the docs, but is there a way to make parts of the randomized terrain to be flat every once in a while?
     
  17. ANTARES_XXI

    ANTARES_XXI

    Joined:
    Dec 23, 2014
    Posts:
    141
    How's it going?
     
  18. DevMerlin

    DevMerlin

    Joined:
    Dec 21, 2011
    Posts:
    96
    Slow, it didn't help that I got sick and have spent the last two weeks recovering. I'm still not sure about the efficiency of these edits but I'll post it soon.
     
  19. ANTARES_XXI

    ANTARES_XXI

    Joined:
    Dec 23, 2014
    Posts:
    141
    Get well soon! Will wait for updates.
     
  20. DevMerlin

    DevMerlin

    Joined:
    Dec 21, 2011
    Posts:
    96
    Okay, I'll be posting this thing Sunday as a .zip file. I want to test both options some more but I'm fairly confident they work well. Both basically modify the function that handles the item creation, either preventing it or allowing it to instantiate the prefab if the rules match. The one thing I'm not sure about is where to post it, I have a personal website but it might not be the best choice. As a very good note, I could potentially be doing this entirely wrong. It seems to clean up objects a lot after each edit. This is the one function modified - the rest of it was adding on the variables:

    public void InstantiatePrefab(Vector3 position, GameObject prefabManager, PrefabPool pool, float angle)
    {

    if (UseDistanceToAppear)
    {
    if (UseGreaterThanDistance)
    {

    } else {

    }
    }

    if (UseRandom)
    {
    float RandomRoll = UnityEngine.Random.Range(RandomChanceMin, RandomChanceMax);

    if (UseGreaterThan)
    {
    if (RandomRoll > RandomOption)
    {
    return;
    }
    } else {
    if (RandomRoll < RandomOption)
    {
    return;
    }
    }
    }


    var prefab = pool.Add(PrefabToClone, position, angle, PrefabToClone.name, MatchGroundAngle);
    prefab.transform.parent = prefabManager.transform;

    //If we have an offset (and we are placing prefabs at an angle), get the direction of that offset.
    //In otherwords, if our offset says to move one up in the y direction, getting the transform direction means the
    //prefab will move one up relative to the rotation it currently has
    Vector3 transformDirection = prefab.transform.TransformDirection(Offset);
    prefab.transform.position = transformDirection + prefab.transform.position;

    Vector3 ModifiedRotation = prefab.transform.rotation.eulerAngles + PrefabToClone.transform.rotation.eulerAngles;
    Quaternion PrefabSystemRotation = Quaternion.identity;
    PrefabSystemRotation.eulerAngles = ModifiedRotation;
    prefab.transform.rotation = PrefabSystemRotation;
    }

    EDIT: Argh, I can't get it to format properly.
     
    Last edited: Jan 31, 2015
  21. DevMerlin

    DevMerlin

    Joined:
    Dec 21, 2011
    Posts:
    96
    Are there any thoughts before I post, ideas on how to better do this?
     
  22. WilcoB

    WilcoB

    Joined:
    Nov 7, 2014
    Posts:
    10
    Does anyone have a version of this asset that keep the terrain between absolute boundaries. A few code snippets were posted to add this functionality, but it doesn't work.
     
  23. appclan

    appclan

    Joined:
    Mar 4, 2015
    Posts:
    1
    Good work on this asset. This is exactly what I have been looking for.
     
  24. xharmagne

    xharmagne

    Joined:
    Apr 3, 2015
    Posts:
    1
    Curious - has anyone tried customizing this asset to randomly generate gaps in the terrain?
     
  25. Basen

    Basen

    Joined:
    Mar 17, 2015
    Posts:
    14
    Greetings,

    Has anyone managed to make caves with this? As in having two instances of the TerrainGenerator?
    Im trying to make it work but am having issues...
     
  26. iamagoatm8

    iamagoatm8

    Joined:
    Apr 1, 2015
    Posts:
    3
    Hi casper, I know it's been a long time since you made this game, but could you share your code which you used to create 2 terrains to get a tunnel effect ?
     
    WilcoB likes this.
  27. tanoshimi

    tanoshimi

    Joined:
    May 21, 2013
    Posts:
    297
    FWIW, I made some modifications to the script to create a 2D edge collider along the edge of the mesh, rather than the 3D top mesh collider that gets generated currently, which means it'll work with Rigidbody2Ds. There's quite a lot of separate hacks in this thread now though, so not sure the best place to try to collate them all together...
     
    tmendez likes this.
  28. tmendez

    tmendez

    Joined:
    Oct 12, 2015
    Posts:
    39
    Omg that's exactly what I need!!! How do I go about doing this?
     
  29. abzs

    abzs

    Joined:
    Jan 9, 2016
    Posts:
    1
    Hello what you have done very well but et the question whether it is possible to apply nibt 2d physics , Edge Collider 2D
     
  30. mihaialin1003

    mihaialin1003

    Joined:
    Feb 9, 2015
    Posts:
    4
    Hi, can you provide me with some starting points for this tweak? I need to integrate 2D physics asap.
    Thank you.
     
  31. FoneFreak

    FoneFreak

    Joined:
    May 17, 2016
    Posts:
    16
    Hi friends, any update on this please?
    it says 2D but seems to generate mesh, is there a simple way of putting a 2d sprite car on top of the mesh?, ie a sprite instead of a texture (like the koala)

    thanks in advance

    Also @tanoshimi, do u have an update on your mod please, Im sure many people would benefit from the ability to user rigidbody2d.

    thanks
     
    Last edited: Jun 20, 2016
  32. zero_null

    zero_null

    Joined:
    Mar 11, 2014
    Posts:
    159
    Hey Guys!
    This asset Looks good but is that really 2D ?
    The Asset is using Mesh Renderer and Mesh Collider which doesn't work with 2D Unity.

    Please help
    thanks
     
  33. hellojbb1234

    hellojbb1234

    Joined:
    Sep 21, 2016
    Posts:
    4
    I have bought(got it for free) your cool thing but I a having trouble with character cause I wanted to stick a Rigidbody on it but that just seems to let it go straight through the mesh collider
     
  34. Gomisan

    Gomisan

    Joined:
    Apr 27, 2015
    Posts:
    5
    Necro thread I know.. but there was soem discussion about a GIT hub for this code so modifications and such could be shared. I'm searching high and low for a way to create terrain like this for a side scroller, but the one major thing I want from it is the one thing the author put in the 'too hard' basket, and that is have the terrain move , not the camera.

    So if anyone has a modified version that does that, I'd be grateful! :)
     
  35. qparampam

    qparampam

    Joined:
    May 8, 2018
    Posts:
    1
    Hi. Can't figure out why I have a different color? Some dark. And how to make sure that the object does not fall down, and perceived as the ground.
     
  36. NSA23

    NSA23

    Joined:
    Sep 23, 2013
    Posts:
    8
    Hello,

    First, thank you for the amazing plugin !

    I would like to ask if someone have a solution to have 2 terrain on the same scene ? I would like to inverse one to get a kind of cave inside the game. Thank you !
     
  37. Cuttlas-U

    Cuttlas-U

    Joined:
    Apr 11, 2017
    Posts:
    38
    hey guys ...

    any one has or can re upload the 2d modification of this asset wich was made by "Shopguy";

    the link dosn't work any more :((

    thank u i really need it ...
     
  38. kk3hi3123

    kk3hi3123

    Joined:
    Aug 17, 2016
    Posts:
    31
    In MeshPiece.cs, make another set of mesh variable (the variables which have a "mech" in their name) and just copy what have been done in the original variable. In my case, I only want to duplicate the front part of the mesh and so:

    Code (CSharp):
    1. private void InstantiateMeshObject()
    2.         {
    3.             MeshObject = new GameObject("MeshPiece");
    4.             if (PlaneType == Plane.Front)
    5.             {
    6.                 MeshObject2 = new GameObject("MeshPiece2");
    7.             }
    8.             AddMeshComponents();
    9.         }
    There are quite a lot of part that have to copy the code and apply to MeshObject2, mesh2, meshRenderer2, meshFilter2 and so on in MeshPiece.cs . And you can change the position in the function CreateMesh. And then update the last function of TerrainPiece.cs:
    Code (CSharp):
    1. private void ParentMeshesToTerrainObject()
    2.         {
    3.             for (int i = 0; i < MeshPieces.Count; i++)
    4.             {
    5.                 MeshPieces[i].MeshObject.transform.parent = TerrainObject.transform;
    6.                 // Mesh Object 2 handle
    7.                 if (MeshPieces[i].MeshObject2 != null){
    8.                     MeshPieces[i].MeshObject2.transform.parent = TerrainObject.transform;
    9.                 }
    10.             }
    11.         }
     
  39. JauntyBearGames

    JauntyBearGames

    Joined:
    Mar 26, 2018
    Posts:
    57
    I've started a github repo to continue improving this great asset, so far I've added
    - support of multi instances
    - support of 2d colliders
    - support physical material
    - pluggable settings via scriptable objects
    - compatible with unity 2019.2

    feel free to contribute and pull requests
    https://github.com/sofielafee/Endless-2D-Terrain-Generator
     
  40. Bylem

    Bylem

    Joined:
    Mar 8, 2020
    Posts:
    2
    I wish the site was still active :(