Search Unity

Procedural content generation -- Where to start?

Discussion in 'Scripting' started by jtsmith1287, Oct 21, 2014.

  1. jtsmith1287

    jtsmith1287

    Joined:
    Aug 3, 2014
    Posts:
    787
    Limit Theory has some pretty incredible procedural space ship generation and I'd like to start my journey learning how to do this. The guy seems like a bad ass and I don't expect to be able to output something that amazing any time soon, but anything similar would be rad.

    I've googled PCG in several ways on several occasions but 99% of the time I'm getting terrain generation so not 100% of what I'm looking for. Regardless, none of the guides/tutorials I've found have decent content for someone who isn't familiar with anything procedural. I'm an experienced programmer, so the only limitations are just the theory. Does anyone know of some good tutorials out there or guides/articles/blogs that detail the basics up to advanced stuff? Or I'd love any wisdom directly from you fine folk. :)
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Well here's an easy way to get started: generate your ships randomly. Then, to make it procedural, all you have to do is seed your random number generator the same way every time you want to make the same sort of ship.

    You can even do this recursively, e.g., the first random number you pull out of the PRNG is the ship class (fighter, scout, carrier, whatever); then you branch to a routine for the type, and it pulls out additional PRNGs for the subparts, and so on till you get down to the details.

    You do need to be careful to do this in a way that's not fragile... you don't want to completely break everything just by adding one more detail feature somewhere (thus pulling out an extra random number, and changing all the subsequent ones). There are various tricks to avoid that. But start here, and I think you'll be headed in the right direction.
     
  3. jtsmith1287

    jtsmith1287

    Joined:
    Aug 3, 2014
    Posts:
    787
    Maybe this goes to show how little I know. What you describe as "generate your ships randomly" is basically what I'm trying to do, haha. That's the part I want to learn. I want to start with nothing, and use C# code to generate a model from scratch. Heck I'd even dig a small code example to get me started.

    Thank you for the wisdom as well. When I get to that stage where things are fragile I'll remember that. :)
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,688
    PCG is a huge field, so you have to start with a tiny project and learn a few steps first, then move onto the next larger project.

    The easiest thing to start with is a procedural starfield generator.

    Trivial I know, but imagine the next step: instead of just little tiny meaningless white dots, what if some number of them are habitable star systems, indicated by a different kind of dot?

    Now you have a random "galaxy" you can begin to build upon!

    Get the above working, and make something that displays your random galaxy right in Unity3D.

    Now allow the player to "enter" a given dot/star system, perhaps by clicking on it.

    For extra points, show the player a little window of information when they hover over a star system that gives them an idea of what is inside.

    When the player enters that dot, fabricate yourself a series of planets around the stars. For now just vary them by size and distance from the sun, perhaps a random color to them, and get all that working.

    How do you choose the colors? Completely randomly? Not really useful... how about out of a table of predetermined colors? Or perhaps hand-paint some different planet shapes? Or maybe paint the planet shapes as layers, each layer being tint-able to different colors?

    Tinker with these ideas a bit, because that will keep you busy for quite some time, and give you a really good idea of how quickly ideas expand when you add more variants and possibilities.

    It will also give you ideas of how to constrain your random choices so that your procedurally generated things are more interesting.

    Kurt
     
  5. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    There is no magic code
    Most 'randomly generated xyz' things have specific sets of things, and then it just chooses things from a list randomly.
    So, where to start is: Create ship parts manually, by hand (thinking about how they can attach to each other), then pick them at random from a list

    Generating complex meshes 'from scratch' is a seriously advanced step.
     
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,688
    Moving from starfields to ships, one way to get interesting spaceships is to first make some random interchangeable parts:

    - engine (drive system that pushes the ship)
    - steering (pivot where the turning happens)
    - weapons module (where guns fire from)

    Now make code that "stamps" these onto some kind of a hollow framework of perhaps "stick like tresses" and then see how they look.

    When you get that working, put functionality into it:

    - make a thruster for the engines
    - make turning for the navigation system
    - make firing for the weapons

    Now attach costs to each of this: strong engine is expensive, good steering is expensive, powerful weapon is expensive... and only give the shipbuilder a budget.

    Now make the game support two of them, and you and your friend can design a ship for each other and go to battle head-to-head.

    Kurt
     
  7. jtsmith1287

    jtsmith1287

    Joined:
    Aug 3, 2014
    Posts:
    787
    Thank you Kurt for the game ideas. :) We actually already have a game and I thought it would be neat to replace our existing ship meshes with procedural ones. I'll poke around with that idea though for a start. Thanks for the ideas guys! (if anyone else has more wisdom please chime in)
     
  8. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Well if your question is really just about how to create meshes in code, the Unity manual has a pretty good section about this.

    Whether you end up using it for your game or not, I do encourage you to play around with procedural mesh generation; it's a lot of fun! (My nugget of wisdom: do not, under any circumstances, attempt to generate a mesh procedurally without sketching out a simple example of said mesh, with the vertices numbered, on a piece of scrap paper, envelope back, or napkin.)
     
    FervInt and Kurt-Dekker like this.
  9. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,688
    I totally back up what Joe Strout said above; learn how to make just simple meshes and you will find your brain opening up in amazing ways to new ideas and new geometry that you can make procedurally. :)

    And yes, draw out your first few mesh ideas on paper otherwise you will really be scratching your head. Remember left hand rule for polys to face the camera, and off you go.

    Kurt