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 Ekta-Mehta-D · Mar 15, 2013 at 12:29 PM · pointfixedjointstickcollision.contacts

Stick Sphere Object to another Sphere Object : 2D

I am developing demo project in that i want to stick sphere below another sphere..

Sample game is Here,..

Actually I am learning unity and do not have knowledge about all concepts so i am not getting way to implement this kind of arrangement of sphere , when i shoot new sphere. how do I get point between two sphere on collision.?

Till now i have generated sphere dinamically at perticular position and shooting functionality also done. Now i get stuck at this point..

Please suggest me some idea. Thanks In Advance For Your Support And Help..

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
2
Best Answer

Answer by robertbu · Mar 15, 2013 at 02:32 PM

If you watch the video, they are not sticking the bubbles to another bubble. They have a set of points which represent the potential positions of the bubbles. When a bubble hits another of a different color, they are sending it to the closest, empty position. By doing it this way, they maintain the order of the bubbles. If this is the functionality you want, I can describe a way to get it.

But to answer your question about getting the position between two bubbles, you could just use Collision.contats to find where it hit, or you can use the position of the two bubbles when they hit and calculate the position:

 function OnCollision(collision : Collision)
 {
     var pointBetween = (collision.transform.position - transform.position);
     pointBetween = transform.position + pointBetween * (0.5 - gap);
 }

Gap is the fraction amount away from the center (so the bubbles are spaced). If gap == 0, then this code will find the spot half way between the two bubbles. There are other ways to calculate this position, but as I mentioned above, it looks like they are sending the bubble to the nearest empty place on the board.

Comment
Add comment · Show 3 · 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 Ekta-Mehta-D · Mar 16, 2013 at 04:35 AM 1
Share

yes sir , i want to sent it to the nearest empty position. Can you please explain me the way of doing it??

avatar image robertbu · Mar 16, 2013 at 06:56 AM 1
Share

The layout for all the levels I saw was offsetting likes like you would find in a hex grid. If I was going to do a lot of levels, I work up an editor, but to get started you can create your levels in Unity. Place all the bubbles in their positions, then mark all the empty positions adjacent to the bubbles by placing a game object at these positions. To make it easy, use something with a mesh. You can turn the renderer after you have done the layout. Something like this:

alt text

$$anonymous$$ake sure all the game objects representing empty, adjacent positions have the same tag. Then in start you can build a list. Something like:

 List emptyList = new List(); 

 void Start () {
     GameObject[] argoEmpty = GameObject.FindGameObjectsWithTag("Empty");
     foreach (GameObject go in argoEmpty)
         emptyList.Add (go.transform);
 }


Now you have a list of all the empty positions. Any time you delete a bubble, you would add the transform of that position to emptyList. Then when you want to find the position, just compare the position of "ball" with all the transforms in the list to find the closest position. Here is an untested method to search the list of transforms:

 Transform ClosestTransform(Transform curr) {
     float fDist = $$anonymous$$athf.Infinity;
     Vector3 v3Curr = curr.position;
     Transform trOut = emptyList[0];
     foreach (Transform trans in emptyList) {
         float fT = (trans.position - v3Curr).sqr$$anonymous$$agnitude;
         if (fT < fDist) {
             trOut = trans;
             fDist = fT;
         }
     }
     return trOut;
 }




hexgridgame2.jpg (96.4 kB)
avatar image Ekta-Mehta-D · Mar 16, 2013 at 07:04 AM 1
Share

ohk. thanks sir. You helped me a lot..

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

11 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

Related Questions

A node in a childnode? 1 Answer

How to place the GameObjects in a sequence on the plane 1 Answer

Draw line from one point to another using mouse 0 Answers

Error Calling DLL function 1 Answer

Apply same amount of force even after gameObjects are fixed joint 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