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. Dismiss Notice

Golf Course Modeling

Discussion in 'World Building' started by emblabac, Jun 3, 2020.

  1. emblabac

    emblabac

    Joined:
    May 16, 2020
    Posts:
    2
    Hey all,

    Total noob here, so pardon any wrong terminology, but I'm struggling with how to build a golf game I've got swirling around in my head. The big question - how to model the course? I see the following 3 options:
    • Probuilder + Polybrush: one will need separate game objects for the fairway, rough, green, etc ... to ensure different physics for each surface (via physics materials). Planes are fine, but how can one create the shapes required for a green (curved surface). When I use Polybrush to try to sculpt I get super jagged results, which are no good for say an undulating fairway or green - perhaps I'm just doing it incorrectly.
    • Terrains: it seems very easy to create the hills and plains required, but they seem massive. I'm also not sure how to create the different physics for each playing surface (e.g. fairway, green, bunker) (custom mesh colliders + physics materials?) (or just multiple terrains?)
    • Model in an external tool (e.g. 3DS Max): I honestly want to avoid this option as it's now another tool I have to learn, but it could just be the way it is.
    On a parallel note, with all of these options I struggle with scale. I know a hole needs to be an area of say 500m^2, how do I create a plane that exact size? Just a 500 x 500 plane in Probuilder? I just am having a hard time with scale in general.

    I'm probably not thinking of other options, so feel free to throw those out there too. This is a hobby for me, I don't plan on becoming a game developer, so please keep that in mind.

    Thanks in advance!
     
  2. CityGen3D

    CityGen3D

    Joined:
    Nov 23, 2012
    Posts:
    680
    My advice would be to keep it simple and just use the Unity Terrain tools, at least for initial experimentation and prototyping. That way you'll get something up and running quite quickly without needing to learn external tools.

    You should be able to get different physics effects on a terrain using texture look-up.
    In this video I'm driving a car over a Unity terrain and the car physics (and effects) behave differently over different surfaces by checking the texture under the wheels. Even though the road, grass and sand textures are on the same terrain mesh.

    So it should be possible to do something similar for golf ball physics, so that at any given moment the physics settings of the terrain are set appropriate to the texture directly below the ball. This approach means it would be very easy to make changes to your course. For instance you could easily put a bunker in by painting sand texture on the terrain and sculpting the height map appropriately.
     
    SmithySFC likes this.
  3. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    3,819
    I actually tried that recently. In my experience this works quite fine:

    * unity terrain tools for the terrain sculpting
    * vegetation studio pro for the planting and for performance of rendering the vegetation; in addition to that the bending of the grass
    * microsplat trax for showing a track when the ball rolls e. g. through the sand
    * tessellation will also be beneficial for effect
    * unity terrain tools for holes where the ball has to fall in
    * enviro for the weather system
    * blender for the modeling & substance painter for the texturing

    And what CityGen3D said about the various physics depending on the texture.

    Mine looked like this. Was just a quick prototype excerpt, here's the grass bending and trax (no tess):



    And then there's the matter of the hole. In my case I painted the hole with the unity tools (2019.3 precondition) and used microsplat mesh blend. Just modeled a hole in Blender and blended it with the terrain like this:

    hole.jpg

    mesh blend 2.jpg
     
    Last edited: Jun 5, 2020
    SmithySFC likes this.
  4. emblabac

    emblabac

    Joined:
    May 16, 2020
    Posts:
    2
    Very cool, thanks guys!

    The terrain tools are super nice looking and quick to build, glad you guys suggested that :) Also, I really dont want to have to model in a new tool.

    I've never even heard of that texture lookup technique. I presume the lookup would be a custom script attached the terrain? (e.g. if texture = sand, then friction = ...)

    Nice idea for the holes. What if however, the placement of the holes is randomized? (e.g. easy position for beginners, more difficult for experts) How would you handle that?

    Also, I'm not familiar with microsplats. I'll have to find some tutorials.

    Thanks!
    Eric
     
  5. unikum

    unikum

    Joined:
    Oct 14, 2009
    Posts:
    58
    You could cut out several holes in the terrain and cover all inactive hole positions with a flat mesh instead of one with the cup in it.
     
  6. SmithySFC

    SmithySFC

    Joined:
    Jan 15, 2021
    Posts:
    11
    Thanks for the terrain lookup tip, its working great for me in my VR app.
     
    CityGen3D likes this.
  7. CityGen3D

    CityGen3D

    Joined:
    Nov 23, 2012
    Posts:
    680
    Oh you're very welcome, thanks for letting me know :)

    Yeah it's a common misconception that you always need separate meshes for different physics, but texture look-up is a really good solution in many instances, and therefore makes terrain objects more versatile than they first appear.

    To be honest I can't really take any credit for the approach. It's a technique I saw demonstrated in @Edy 's vehicle physics assets a few years back. He may be able to confirm whether this is in the Free version of Edy Vehicle Physics for anyone wanting a demo of the approach.
    But essentially it's just a script that raycasts to do a texture sample at a contact point and then conditional logic based on the results to match up different textures to different Physic Materials.
     
  8. SmithySFC

    SmithySFC

    Joined:
    Jan 15, 2021
    Posts:
    11
    This C# code snippet with some additional terrain variable setup should be enough for anyone to understand how they could use this.
    <quote>
    public void GetTerrainTexture()
    {
    ConvertPosition(gameObject.transform.position);
    CheckTexture();
    }

    private void ConvertPosition(Vector3 ballPosition)
    {
    Vector3 terrainPosition = ballPosition - terrain.transform.position;

    Vector3 mapPosition = new Vector3
    (terrainPosition.x / terrain.terrainData.size.x, 0,
    terrainPosition.z / terrain.terrainData.size.z);

    float xCoord = mapPosition.x * terrain.terrainData.alphamapWidth;
    float zCoord = mapPosition.z * terrain.terrainData.alphamapHeight;

    posX = (int)xCoord;
    posZ = (int)zCoord;
    }

    // This retrieves "Alpha Maps" for terrain FOR 10 TEXTURES - SET AS NEEDED.
    private void CheckTexture()
    {
    float[,,] aMap = terrain.terrainData.GetAlphamaps(posX, posZ, 1, 1);
    textureValues[0] = aMap[0, 0, 0];
    textureValues[1] = aMap[0, 0, 1];
    textureValues[2] = aMap[0, 0, 2];
    textureValues[3] = aMap[0, 0, 3];
    textureValues[4] = aMap[0, 0, 4];
    textureValues[5] = aMap[0, 0, 5];
    textureValues[6] = aMap[0, 0, 6];
    textureValues[7] = aMap[0, 0, 7];
    textureValues[8] = aMap[0, 0, 8];
    textureValues[9] = aMap[0, 0, 9];
    }

    public void ExamineTerrain()
    {
    GetTerrainTexture();

    string sMsg = "";

    if (textureValues[0] > 0)
    sMsg = "GRASS 1 [" + textureValues[0].ToString() + "]";

    if (textureValues[1] > 0)
    {
    sMsg = "STONE 1 [" + textureValues[1].ToString() + "]";
    }

    if (textureValues[2] > 0)
    {
    sMsg = "SAND 1 [" + textureValues[2].ToString() + "]";
    }

    if (textureValues[3] > 0)
    {
    sMsg = "GRASS 2 [" + textureValues[3].ToString() + "]";
    }

    if (textureValues[4] > 0)
    {
    sMsg = "STONE BROWN [" + textureValues[4].ToString() + "]";
    }

    if (textureValues[5] > 0)
    {
    sMsg = "CLIMBABLE ROCK [" + textureValues[5].ToString() + "]";
    }
    if (textureValues[6] > 0)
    {
    sMsg = "ROCK 2 [" + textureValues[6].ToString() + "]";
    }
    if (textureValues[7] > 0)
    {
    sMsg = "ROCK 3 [" + textureValues[7].ToString() + "]";
    }
    if (textureValues[8] > 0)
    {
    sMsg = "SAND 2 [" + textureValues[8].ToString() + "]";
    }
    if (textureValues[9] > 0)
    {
    sMsg = "GRIDDED [" + textureValues[9].ToString() + "]";
    }
    Debug.Log("Ball-->Landed on Terrain: " + sMsg);
    }
    </quote>
     
    Tchotchke9366 likes this.
  9. SmithySFC

    SmithySFC

    Joined:
    Jan 15, 2021
    Posts:
    11
    Great work, I'm trying to figure out how to blend my golf hole similar to your model to my terrain? Any guidance would be appreciated. Thanks