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 TargonStudios · May 16, 2014 at 02:07 AM · 2djavascriptblocks

How to detect if player made building is air-tight(2D)

So, I am making a 2D block based game. I need to be able to tell if a custom, player made building is completely air-tight (So pretty much detecting if it is a completed house, with no holes outside). I had an idea how to do this, but I don't think it will work. Here was my first Idea-

So I was going to make an empty game object that would float around the inside of the building with ray casts on all sides checking to make sure there is a wall on all sides. When the game object hit a wall, it would go another way. If it found that there was a wall missing, it wouldn't be air-tight. Problem is, this probably isn't the best way to do this, and I don't know how I would spawn it in the building in the first place(How I would be able to check if one needs to be spawned).

So, I don't really know how to approach this. Steering me in the right direction would help me out a lot. If there is another post on this or a tutorial you know that could help me, I would appreciate if you could comment it.

Bonus: What would be a good way to get all the air blocks in the room (once it detects the room is air-tight) into a group? Any ideas for that would be greatly appreciated.

Comment
Add comment · Show 2
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 Kiwasi · May 16, 2014 at 02:28 AM 2
Share

Google "flood fill". technique might be of value.

avatar image TargonStudios · May 16, 2014 at 11:02 AM 0
Share

Thanks! Looked it up and read about it, just thought of how I might do it! Really helped.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Cherno · May 16, 2014 at 02:20 AM

It depends how your grid system works. It would be easiest if you have a 2-dimensional int array that takes xy coordinates to set the contents of this coordinate, like 0 for nothing, 1 for wall, 2 for door or whatever. Then you can just iterate through all positions and check each one's neighbors, so that when an "in-house" coordinate has a neighbouring "not-in-house" block, you know that it's not airtight.

If you are using actual gameobjects for each grid space, you can either do the same, or use four raycasts for each in-house space.

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 TargonStudios · May 16, 2014 at 02:37 AM 0
Share

First option seems the best, Ill have to change it around a bit but seems its like a good idea, didn't think of it. Also, you mention checking a neighbouring block, what would be the best way to do that?

avatar image Cherno · May 16, 2014 at 01:34 PM 0
Share
 public int xSize = 10;
 public int ySize = 10;
 public bool airtight;
 public int[,] fillData;//0 = nothing, 1 = inside house, 2 = outside house, 3 = ...
 
 
 void checkIfAirtight() {
      airtight = true;
      for(int i = 0; i < xSize; i++) {
           for(int y = 0; y < ySize; y++) {
                if(x - 1 == 2 || x + 1 == 2 || y - 1 == 2 || y + 1 == 2) {
                     airtight = false;
                }
           }
      }
      if( airtight == true) {
           Print("House is airtight!");
      }
      else {
           Print("House is not airtight!");
      }
 }
 

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

22 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

Related Questions

Making the players head face toward the location of the mouse? 1 Answer

Mouse Click to keyCode 1 Answer

Create clickable GameObjects (JS) 1 Answer

Evac city outdated? 0 Answers

Creating a Shadow tail for a 2D Character when walking 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