Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by Nallelcm · Aug 29, 2012 at 06:07 PM · fpswallsmaze

How to create wall at runtime?

Hi, I'm fairly new to Unity. I haven't made anything that anyone could call a game, right now I'm just trying different things out seeing how they work. I'm thinking I'm about ready to make my first 'game'.

The concept is very simple, it will be a randomly generated maze that the player has to navigate (first person) to get to the exit point, moving on to the next level.

I'm thinking that a good starting point would be the level generation. I am wondering what the best approach would be.

This is my thought process so far:

  • Have a plane for the floor, manually setting the Y location so that my wall prefabs fit nicely when they have a y position of 0

  • Since there would be no movement on the Y axis all I'm concerned with the X and Z locations of the walls.

  • I thought it would be nice to have thin walls but after considering it, I think it may be easier to have the 'walls' fill a whole cell.

  • I want the maze to be scalable starting small and getting larger. 100x100 at the maximum (this may be too large to be practical, but just throwing that out there as a hard max).

  • Using a cube as the wall object, I generated a 100x100 grid filled with 1x1x1 cubes. I noticed a significant performance hit (obviously that is a lot of objects).

  • I thought about scaling the cubes to reduce the number of objects loaded into the scene (ex: 4 walls in a row along the x axis would be 1 cube scaled out 4, instead of 4 individual cubes). I ran into some positioning problems.

Anyway the point of this thread is to ask what any of you guys would suggest in so far as building these walls. What would be the most inexpensive way to achieve what I'm looking for?

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

3 Replies

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

Answer by ScroodgeM · Aug 29, 2012 at 06:45 PM

if you interesting in inexpensive way to draw all these geometry, best way is to generate it procedurally at runtime. this let you do all scene in one drawcall and without unneeded hided geometry like down-faced sides.

not so clean but also good way is to combine meshes in one big mesh.

simple mesh generator - MeshGenerator.cs

using UnityEngine; using System.Collections;

public class MeshGenerator : MonoBehaviour { private GameObject tmpobj; void Start() { tmpobj = new GameObject(); MeshFilter mf = tmpobj.AddComponent();

tmpobj.AddComponent(); tmpobj.name = "Plane"; tmpobj.renderer.material.color = new Color(0.9490f, 0.8901f, 0.7686f, 0);

Vector3[] verts = new Vector3[4]; Vector2[] uv = new Vector2[4]; Vector3[] normals = new Vector3[4]; int[] tri = new int[6];

verts[0] = new Vector3(0f, 0f, 0f); verts[1] = new Vector3(0f, 1f, 0f); verts[2] = new Vector3(1f, 1f, 0f); verts[3] = new Vector3(1f, 0f, 0f);

normals[0] = new Vector3(0f, 0f, 1f); normals[1] = new Vector3(0f, 0f, 1f); normals[2] = new Vector3(0f, 0f, 1f); normals[3] = new Vector3(0f, 0f, 1f);

uv[0] = new Vector2(0f, 0f); uv[1] = new Vector2(0f, 1f); uv[2] = new Vector2(1f, 1f); uv[3] = new Vector2(1f, 0f);

tri[0] = 2; tri[1] = 0; tri[2] = 3;

tri[3] = 1; tri[4] = 0; tri[5] = 2;

Mesh mesh = new Mesh(); mesh.name = "Plane"; mesh.vertices = verts; mesh.triangles = tri; mesh.uv = uv; mesh.normals = normals; mf.mesh = mesh; } }

Comment
Add comment · Show 6 · 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 Nallelcm · Aug 29, 2012 at 06:50 PM 0
Share

So if I understand this correctly. i would make a vector3 array containing the edge points of all the walls?

avatar image ScroodgeM · Aug 29, 2012 at 08:38 PM 0
Share

correct. than make triangles to make rendering surfaces. simply all 8)

avatar image ScroodgeM · Aug 29, 2012 at 08:54 PM 0
Share

added example of generator

avatar image Nallelcm · Aug 29, 2012 at 09:29 PM 0
Share

Thanks for the example! that is fantastic!

i understand the verts, but im confused as to what tri, uv, and normals are

avatar image ScroodgeM · Aug 29, 2012 at 09:43 PM 0
Share

tri is triangle. each triangle should have 3 verts. in this example there are 2 triangles, it's $$anonymous$$imum to cover square.

uv is texture mapping

http://en.wikipedia.org/wiki/Texture_mapping

normals are used for lighting.

http://en.wikipedia.org/wiki/Normal_(geometry)

i'm sure it's a lot of information about it over unity answers and internet. these are basics for 3d modelling.

ask if you still need some explain

Show more comments
avatar image
0

Answer by GlitchBait · Aug 29, 2012 at 06:48 PM

It may be easier and provide more control by fabricating each maze manually beforehand, so you can have the player progress through each more advanced maze by moving to the next scene.

Instantiating the maze from empty game objects would look really cool! (having the walls drop into place from far away moving to the player camera and around them.

Edit Instantiating wall sections at a time, not cubes. I should have clearified.

Comment
Add comment · Show 1 · 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 Nallelcm · Aug 29, 2012 at 06:59 PM 1
Share

The fabrication of the maze before hand is an option i guess.. I would prefer to avoid it as I would like the randomness (also since im going to be the only one playing the game, it makes it more interesting for me ;) )

avatar image
0

Answer by Piflik · Aug 29, 2012 at 06:49 PM

I would probably go the cube way...but delete the top and bottom faces. That would be 8 faces per cube. With 100² cubes, that would be 80k triangles, which is not much (for PC). Also you would never need that many cubes on a 100² grid, since you would only need those left and right of the path. The rest would be empty.

Comment
Add comment · Show 2 · 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 Nallelcm · Aug 29, 2012 at 07:00 PM 0
Share

Does the amount of objects in the scene affect performance? Also how would I remove the upper and bottom faces?

avatar image Piflik · Aug 29, 2012 at 08:08 PM 0
Share

You can remove the top and bottom in any modeling program (Blender is free).

Both the amount of objects and the amount of faces affect the performance.

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

10 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

Related Questions

Patching glitches 1 Answer

RigidbodyFPSWalker climbing walls 2 Answers

Moving through walls 4 Answers

Importing a wall with doorway into unity, but rigid body/collider is affecting the door way (empty gap) 1 Answer

Setting camera pitch - Never works? 0 Answers


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