Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Wolfrik_Creations · May 28, 2016 at 01:42 AM · terrain3d modelsmesh manipulationroads

How Can I make 3D Roads?

So the title kind of explains it, I need to make 3D roads similar to Unturned's road system how do I accomplish this?

I should probably note that it will need to go across the terrain too, so it has to be able to manipulate itself to the terrain and look natural, I have a 3D model for the road but I just need to be able to place it via nodes and the need to connect to each other.

Thanks in advance!

Also sorry for asking a lot of questions lately, I don't know if that bothers some people or not but I just recently found out that I was supposed to leave my questions in "Default" and they get answered now so I can finally get some assistance on all of the problems I've been having, most have been resolved thanks to you guys!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by cjdev · May 28, 2016 at 07:05 AM

What you want to do isn't trivial but it looks like that road system you linked creates a procedural mesh by connecting quads between given waypoints. If that's what you're after then you'll need to start by creating a single quad procedurally and then expanding by increasing the number of vertices for each road section. Here's the bare-bones of how to create a grid of quads procedurally:

 public void CreateMesh(int size)
  {
      List<Vector3> verts = new List<Vector3>(); // Index used in tri list
      List<int> tris = new List<int>(); // Every 3 ints represents a triangle
      List<Vector2> uvs = new List<Vector2>(); // Vertex in 0-1 UV space
      for (int i = 0; i < size; i++)
      {
          for (int j = 0; j < size; j++)
          {
              verts.Add(new Vector3(i, 0, j));
              uvs.Add(new Vector2((float)i / size, (float)j / size));
              if (i == 0 || j == 0) continue; // First bottom and left skipped
              tris.Add(size * i + j); //Top right
              tris.Add(size * i + (j - 1)); //Bottom right
              tris.Add(size * (i - 1) + (j - 1)); //Bottom left - First triangle
              tris.Add(size * (i - 1) + (j - 1)); //Bottom left 
              tris.Add(size * (i - 1) + j); //Top left
              tris.Add(size * i + j); //Top right - Second triangle
          }
      }
      Mesh mesh = new Mesh();
      mesh.vertices = verts.ToArray();
      mesh.uv = uvs.ToArray();
      mesh.triangles = tris.ToArray();
      mesh.RecalculateNormals();
      
      GameObject grid = new GameObject("Grid");
      grid.AddComponent<MeshFilter>();
      grid.AddComponent<MeshRenderer>();
      grid.GetComponent<MeshFilter>().mesh = mesh;
      // Load a material named "GridMat" from a folder named "Resources"
      MaterialgridMat = Resources.Load<Material>("GridMat");
      grid.GetComponent<Renderer>().material = gridMat;
  }

That should be enough to get you started, but you'll have to adjust it to be a "grid" with one base square and x waypoints for height along with the custom positions from the waypoints. As for connecting the roads... that's a whole other beast entirely and one you might want to focus on once you have roads in place.

Comment
Add comment · Show 9 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Wolfrik_Creations · May 28, 2016 at 07:22 AM 0
Share

Thank you very much! Sadly it's 3:20 A$$anonymous$$ where I am and I don't have time to test it, I will try it first thing in the morning though.

Thank you for taking your time to make this! :)

Also, quick question; is this an editor script or how does it work?

avatar image cjdev · May 28, 2016 at 07:30 AM 0
Share

It's a method that you would put in a script on a GameObject in your scene and call when you wanted to make a grid of size x size.

avatar image Wolfrik_Creations cjdev · May 28, 2016 at 07:34 AM 0
Share

I'm not looking to make roads at runtime, I just want to make them baked into the map so that there are roads in the game.

I cannot model each road themselves because I don't think it's possible to open your Unity terrain in Blender, is it?

avatar image cjdev cjdev · May 28, 2016 at 08:04 AM 1
Share

That is significantly easier, and yes you can export your terrain as an obj file and use it as a template to model your roads in Blender. Take a look at this script, should get you started.

avatar image Wolfrik_Creations cjdev · May 28, 2016 at 08:20 AM 0
Share

Thank you very very much!

I have not tested it yet but it's also JavaScript which is good for me.

I'm going to sleep in about 20 $$anonymous$$utes, after I watch an episode of a show, but does this export textures as well? If so I can literally stop using the default Unity terrain and just use my prefab trees and finally make caves and such.

Thank you again for the help!

I'm really starting to love Unity Answers. xD

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

49 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

using height brush on plane? 2 Answers

How would one achieve the cliffs in dota2 terrain? 2 Answers

Painting Roads on Terrain 1 Answer

how to produce endless terrain illusion? 1 Answer

How to manipulate the Shape of a 3D object at runtime 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges