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 Napalm1432 · Jun 09, 2013 at 01:31 PM · vector3gridalign

comparing transform positions with those from a vector3 array

I'm creating a bubble shooter and although i have most parts working i'm stuck at the part where a ball should be aligned to a grid, and tracking wich balls are attached to the other. I got to the part to create a grid and saving positions to an array, but i can't seem to figure out how to compare it to the values of the array, and i still have no idea how i'm going to implement the tracking of the attached balls..

Here's the script wich creates the grid, the balls have seperate scripts.

 var positionPrefab : Transform;
 ;
 function Start () 
 {
     for(var u : int = 0; u < 17; u++)
     {
         for(var v : int = 0; v < 15; v++)
         {
         Instantiate(positionPrefab, Vector3((u * 10) -75, (v * 10) - 70, 0), Quaternion.identity);
         }
     }
     var gridPositions = GameObject.FindGameObjectsWithTag("gridPosition");
     var positionLength = gridPositions.length;
     var positions :Vector3[] = new Vector3[positionLength];
     
     for(var i = 0; i < positionLength; i++)
     {
     positions[i] = gridPositions[i].transform.position;
     
     //player[0].transform.position.x;
     
     print(positions[i]);
     }
 }
 
 function Update () 
 {
 
 }
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

Answer by robertbu · Jun 09, 2013 at 03:16 PM

The bubble games I'm aware of layout the bubbles so that every-other line is shifted. The result is that if you take any one bubble from the middle of the layout it will have six neighbors, all equal distant. You can think of the bubbles as being position on a hex grid. Given this layout, it is easy to determine neighbors. You can run through an array of position and look for any bubbles less than a threshold value. Or you can just use Physics.OverlapSphere() to find the neighbors. For deleting, you would recursively detect bubbles of the same color.

It looks like to me you implemented a rectangular grid. I don't think this works well for a bubble game since neighbors are unclear both to the player and to your code.

I know there is at least one other "thread of questions" about bubble shooting. Here is one answer:

http://answers.unity3d.com/questions/417477/stick-sphere-object-to-another-sphere-object-2d.html

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

14 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

Related Questions

Round a Vector3 to a grid position? 2 Answers

How can i keep global scale of object while instantiate it 1 Answer

Return grid points within a cube selection 1 Answer

Transform angle to grid position 2 Answers

c# : Accessing Struct variables inside an Array 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