Search Unity

Endless 2D terrain

Discussion in 'Made With Unity' started by tombali, Mar 8, 2013.

  1. tombali

    tombali

    Joined:
    Jun 7, 2012
    Posts:
    132
    ...inspired by this video.

    Take a look at this link. Press space to jump.

    Player controller reacts if you land bad or right and there's basic coins system.

    :)
     
  2. SunnySunshine

    SunnySunshine

    Joined:
    May 18, 2009
    Posts:
    977
  3. Deleted User

    Deleted User

    Guest

    Nice. It tends to glitch a lot when I mess with the sliders. First thing I thought of was Ski Safari. Nice job.
     
  4. tombali

    tombali

    Joined:
    Jun 7, 2012
    Posts:
    132
    tnx :)

    yes, sliders are there for presentation mainly, so you can see all configurations terrain can get. it wouldn't be recommended to mess with them too much (in fashion of making big changes to values) when you run real game.
     
  5. holokaust

    holokaust

    Joined:
    Nov 17, 2009
    Posts:
    18
    Very nice man!!

    Is there any way you could share the source or help me make something similar? I'm trying to achieve something like this but dont know where to start.

    Cya!
     
  6. xtremepman

    xtremepman

    Joined:
    Jul 18, 2012
    Posts:
    388
    Yes! Share it with the world!
     
  7. ratjar_games

    ratjar_games

    Joined:
    May 13, 2012
    Posts:
    17
    @tombali, cool man! Care to share the project?
     
  8. tombali

    tombali

    Joined:
    Jun 7, 2012
    Posts:
    132
    It wouldn't be fair to prime31. Just watch code part in video carefully and you should create this kind of endless terrain in less than a day :D
     
  9. ratjar_games

    ratjar_games

    Joined:
    May 13, 2012
    Posts:
    17
    Hi @tombali, I've managed to get it working, off that video, all good. The only problem I'm having is that the segments don't match with height, and have a steep drop/incline seem, ideas of which values I should change? (I've been playing with them all)

    $Screen Shot 2013-03-20 at 14.29.06.png

    Thanks.
     
    Last edited: Mar 20, 2013
  10. tombali

    tombali

    Joined:
    Jun 7, 2012
    Posts:
    132
    Hi,

    just check your code and compare it with one in the video. There're many math operations and one wrong can mess everything up. When I first time tested code, I also had similar situation. Then I checked the code and found few typos. If you fix them, everything should wok just fine.
     
  11. DougMcFarlane

    DougMcFarlane

    Joined:
    Apr 25, 2009
    Posts:
    197
    If it helps any, I answered a question on the Stack Exchange - Game Development site, which outlines this concept.
    It is programmed in GLBasic however, but the math and logic should be applicable. (But no colliders!)

    http://gamedev.stackexchange.com/qu...aths-behind-raiden-2-purple-laser/29469#29469

    I had a hard time stitching the UV coordinates between the chunks, but eventually got it looking ok.
    Is there an easy (or automatic!) way of doing this in Unity? (ie. stretch a texture across multiple UVs, and repeat?)
     
    Last edited: Mar 20, 2013
  12. ratjar_games

    ratjar_games

    Joined:
    May 13, 2012
    Posts:
    17
    You were totally right! I was banging my head against the wall yesterday as I couldn't see anything but tried again this morning and ended up finding a * instead of a + ;) Thanks for your help!
     
  13. tombali

    tombali

    Joined:
    Jun 7, 2012
    Posts:
    132
    I'm glad you made it :) And I think you've learned something new, so this is much better then just downloading complete code.
     
  14. ratjar_games

    ratjar_games

    Joined:
    May 13, 2012
    Posts:
    17
    Haha same, I always am, and now I have the code for any future reference ;)

    By the way, how did you overcome the 'floating point accuracy' problem past 10,000 on the x axis?

    I'm thinking of snapping everything back, I don't know how badly it would affect the physics... but I can't think of another solution as I don't want to move the environment because that would surely mean more overhead..

    :)
     
  15. Rakeshchatra

    Rakeshchatra

    Joined:
    Feb 28, 2013
    Posts:
    6
    any plans of releasing the demo project ???
     
  16. Rakeshchatra

    Rakeshchatra

    Joined:
    Feb 28, 2013
    Posts:
    6
    Iam not getting how you are generating the continuous terrain along the x axis and how you are removing it.. Please release the demo project..
     
  17. Rakeshchatra

    Rakeshchatra

    Joined:
    Feb 28, 2013
    Posts:
    6
    only mesh 1 and mesh 2 gameObjects are creating on the awake.. but their meshes are not creating.. Please help me.
     
  18. dev1791

    dev1791

    Joined:
    Mar 20, 2013
    Posts:
    35
    Those who have been able build this code, would you care to mention what is in the constructor for the Terrain class?

    This is what I get as the result when I built the code.

    $error.jpg
     
    Last edited: Jun 2, 2013
  19. dorpeleg

    dorpeleg

    Joined:
    Aug 20, 2011
    Posts:
    250
    I can't seem to compile it.
    I'm getting :
    I called my script "OrthographicTerrain" instead of "Terrain" so I wont get confused with unity's Terrain.
    But other then that, its a copy paste.

    Any ideas?
    And, anyone that got it working mind sharing the other parts of the script (the ones we can't see in video)?
     
  20. dorpeleg

    dorpeleg

    Joined:
    Aug 20, 2011
    Posts:
    250
    Ok, I changed this:
    Code (csharp):
    1. TheTerrain = new OrthographicTerrain(gameObject);
    To this:
    Code (csharp):
    1. TheTerrain = new OrthographicTerrain();
    2.         TheTerrain.TheTerrainGenerator = new TerrainGenerator();
    And now the terrain is generated.

    But I have other problems.

    1. It seems the the 1st generated terrain is always the same and not random.
    2. When getting to the point another terrain is ment to be generated, I get this error:
    For the GenerateMeshWithWidth funcation.

    Any ideas?
     
  21. dorpeleg

    dorpeleg

    Joined:
    Aug 20, 2011
    Posts:
    250
    nvm, solved :p
     
  22. cops52

    cops52

    Joined:
    Jun 11, 2013
    Posts:
    30
    Very cool.
     
  23. dorpeleg

    dorpeleg

    Joined:
    Aug 20, 2011
    Posts:
    250
    Hey,
    I was wondering how the player object is built.
    I want it to stick to the ground all the time and only have "air time" when I press a button.
    how should i achieve this?
    Any help will be appreciated.
     
  24. TenaciousLibbs

    TenaciousLibbs

    Joined:
    Nov 26, 2012
    Posts:
    9
    Having a problem with the cameracontroller script, particularly the line:

    private DigitalAverage _heightAverage = new DigitalAverage();

    getting the error "type or namespace could not be found. Are you missing a using directive or an assembly reference?"

    Any help would be much appreciated!

    Thank you.
     
  25. JackJick5000

    JackJick5000

    Joined:
    Mar 25, 2015
    Posts:
    4
    Works great, but the scaling is huge!!!
    How did he made the PlayerController on that scaling?