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 kromenak · May 09, 2011 at 05:04 PM · griddraginventoryalgorithm

Algorithm for Finding Shapes on a Grid

Hey guys,

I'm working on a problem that is similar to the "inventory tetris" idea where you have an x by y grid upon which you have differently shaped inventory items. Like this: http://gangles.ca/images/screenshots/InventoryTetris_Title2.png

The problem I'm having is that, while the player is dragging an object, I'd like to highlight groups of grid cells that are the right size for the object to fit. So, if the player is dragging an L-shaped gun or something, all the L-shaped areas on the grid matching the object's orientation would light up so it is obvious where the object can be placed.

I'm having a lot of trouble figuring out what sort of algorithm I can use to achieve this. I imagine I might be able to use a depth-first search to find the different available areas. But I'm really unsure how I could detect if the area has the correct shape for whatever is being dragged.

I feel like this is the sort of problem that has been solved before, but I'm having trouble identifying existing algorithms that will be helpful. Does anyone have any leads on an algorithm or procedure that would help out with this?

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 kromenak · Jun 10, 2011 at 10:40 PM

Thought I'd get back and mention how I was able to solve this issue.

First off, I converted the rigidbody's colliders into a 2D array of 1s and 0s. For example, an L shaped object would have this array:

 100
 100
 111

I did this by using the minimum collision bounds of the object as the origin for a coordinate system, and then converting the min/max points of each contained collider to that coordinate system. This would give me something like "bounds.min = 0,0" and "bounds.max = 2, 0" - from there, I could fill in all intervening spaces with 1s.

After this, I also kept track of whether grid spaces were occupied using a 1 and 0 system. From there, it was a simple matter of iterating over the grid and seeing if the shape's array would fit anywhere in the larger grid. If any 1s overlapped, the position was invalid.

Comment
Add comment · 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

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

2 People are following this question.

avatar image avatar image

Related Questions

Bad piggies-like inventory? 0 Answers

Limiting an inventory system + dragging items in inventory window... 0 Answers

dragging objects horizontally in a grid or in increments 2 Answers

GUI grid of buttons issue. 1 Answer

Swipe Movement On A Grid 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