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
0
Question by Dartmor · Aug 04, 2014 at 03:20 PM · randommaze

Create passages in round maze

I've tried to find the answer by myself, but didn't succeeded so far.

I've making round maze. After instantiating every circle of walls ( for every circle - copy of the same script, because i need different number of wall parts in every circle ), the part of the wall has 10% chance to be destroyed - it creates passages by now. The problem is that it's not a good solution, i need not more than 3 passages in every circle of walls. But with random it can be more than 3, or even zero.

So how to limit the number of passages in instantiated circles of walls? Maybe it's better to make circle of walls by hand, without instantiating them and give every part of the wall unique name, and then make if/else with random? For example, 10% that Wall 1 will be destroyed, and if not, 10% that Wall 2 will be destroyed. And when 3 parts will be destroyed, end the chain. But isn't it a hard way? alt text

maze.jpg (329.0 kB)
Comment
Add comment · Show 3
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 robertbu · Aug 04, 2014 at 03:21 PM 0
Share

It is hard to be specific without your source code. I assume you know how many wall segments go into each wall. Just pick three (or however many) before you generate each circle, and don't generate a wall segment if the segment number is one of the three.

avatar image Dartmor · Aug 04, 2014 at 03:26 PM 0
Share

Wall Generation:

Blockquote

public class Walls1 : $$anonymous$$onoBehaviour { public GameObject prefab; public int numberOfObjects = 20; public float radius = 5f; void Start () { for (int i = 0; i < numberOfObjects; i++) { float angle = i $$anonymous$$athf.PI 2 / numberOfObjects; Vector3 pos = new Vector3 ($$anonymous$$athf.Cos (angle), 0, $$anonymous$$athf.Sin (angle)) * radius; GameObject Wally = Instantiate (prefab, pos, Quaternion.LookRotation(-pos)) as GameObject; Wally.transform.parent = transform; Wally.AddComponent(); } } Each part of the wall receive script: > Blockquote void Start () { var theRange = Random.Range(0,12); if (theRange == 1) { Destroy (gameObject); } } }
avatar image jamesflowerdew · Aug 04, 2014 at 03:44 PM 0
Share

I'd make your choices before you go into the loop and create the objects. get your three random numbers based on "numberOfObjects" and then have an if inside your for loop saying something like this.

 for (int i = 0; i < numberOfObjects; i++) {
 if (luckynumbers[0]==i||luckynumbers[1]==i||luckynumbers[2]==i){
 //Don't build it
 }else{
 //build it
 }
 }

1 Reply

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

Answer by robertbu · Aug 04, 2014 at 03:47 PM

I cannot think of a slick way to do this. Here is a brute force way. It generates a generic list of all the possible segments, and then eliminates all but a specified number. At the top of the file put:

 using System.Collections.Generic;

Then Add this function:

 List<int> FindHoles(int totalSegments, int holeCount) {
     List<int> holes = new List<int>();
     for (int i = 0; i < totalSegments; i++) {
         holes.Add(i);
     }
     while (holes.Count > holeCount) {
         holes.RemoveAt (Random.Range (0,holes.Count));
     }
     return holes;
 }

Then your generation code would be:

 void Start () {
     List<int> holes = FindHoles(numberOfObjects, 3);
 
     for (int i = 0; i < numberOfObjects; i++) {
         float angle = i * Mathf.PI * 2 / numberOfObjects;
         Vector3 pos = new Vector3 (Mathf.Cos (angle), 0, Mathf.Sin (angle)) * radius;
 
         if (!holes.Contains(i)) {
              GameObject Wally = Instantiate (prefab, pos, Quaternion.LookRotation(-pos)) as GameObject;
              Wally.transform.parent = transform;
              Wally.AddComponent<D>();
          }
        }
     }

Note I've specified 3 for the holeCount. This value could be randomly generated, or it could be a fraction of the total number of segments. Also with this code, you don't need the scrip on each segment, since hole objects are never created.

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 Dartmor · Jun 06, 2015 at 06:09 AM 0
Share

http://answers.unity3d.com/questions/981285/difficult-question.html

pls help robertbu :P

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How do I randomly place doors, treasure chests, and traps in a randomly generated maze? 0 Answers

Randomly spawn a trigger area 1 Answer

Starting a roguelike, maze generator problem. 1 Answer

How to randomize my maze generation algorithm(DFS & stacks) 1 Answer

Random Range BUT only on specific Co Ords 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