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 darthbator · Oct 01, 2013 at 06:27 PM · arraygridpuzzle2d array

Tracking ojects grid positon

So Recently I have been trying to figure out how I would go about putting together a rudimentary puzzle game system inside of Unity. Something based in blocks of a static size and shape. What I arrived at was that I should create a 2D gird using a 2D array that could then store the positions of all of the various puzzle objects in the grid. That would be easy to loop through and check for matches and etc. My biggest question is really how I would go about tracking the position of the puzzle objects inside that array!

I was also wondering about the "best" way to go about establishing that 2 dimensional grid. This question is sort of broad. Please ask away in the comments if you need me to expand on anything here. Thanks a lot for the help!

Comment
Add comment · Show 1
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 · Oct 01, 2013 at 07:36 PM 0
Share

Nailing down an approach will depend on the details. A reference to a similar game would be very helpful. How does your game relate to these where all the blocks are square, same size and do not rotate?:

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by programmrzinc · Oct 01, 2013 at 08:38 PM

hmmm. What i would do is scale the 'grid' based on real world positions.

Like if a 1 unit cube is at 0,0 in your game, the real coordinates would be at

Vector3(0.5f,0.5f, 0)

That way, all you need to do is pass the coordinates through a function to extract the game coordinates from the real word position

 void GetPos(GameObject tempGO){
      Vector3 gameLoc;
      gameLoc = new Vector3(tempGO.position.x - 0.5f, tempGO.position.y - 0.5f, 0);
      //Assign gameLoc to a public variable to use. 
 
 }
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

15 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

Related Questions

2d Array persists during multiple game sessions 2 Answers

2D Array of GameObjects... 1 Answer

Determining groups in a 2D array by checking neighbours (and their neighbours etc) 2 Answers

I'm having trouble with grids and instantiating arrays of prefabs. 1 Answer

Using a list of arrays to make Unity UI 2D button toggle colors 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