Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
This question was closed Apr 18, 2016 at 03:19 AM by Fujitaka for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Fujitaka · Apr 18, 2016 at 12:10 AM · gameobjectsmerge

Merging two Gameobjets into one!

Hey guy's, I'm trying to figure out a way to merge two game objects the way I want them to, but I have no idea how to even begin... Here's the deal:

I've got a 2D platformer where you can shoot projectiles called blobs. Those blobs are just cubes with dimestions of 0.1, 0.1, 0.1 for now. I'd like them to merge into a bigger "blob" when they collide (or come close to each other) and this bigger blob should have the same properties so that when a smaller blob hits it, they merge and the blob gets even bigger. So that 2 blobs merge into one blob with dimensions of 0.2, 0.2, 0.2 and when another small blob hits it, they merge into a blob with dimensions of 0.3, 0.3, 0.3 and so on.

I hope I wrote that in a way that it is understandable, because like I said, I have no idea how to even begin... To make things a bit more simple, you can just give me some tips to how I can do that, instead of writing the whole code for me, since I'm in the process of learning and wouldn't mind if I had to figure out the specifics myself (that doesn't mean I'd dismiss written code ^^).

When you need more information's about the blobs (or anything really), I will of course try to provide them as fast as I can!

Thank you in advance, and have a nice day!

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

  • Sort: 
avatar image
1
Best Answer

Answer by TBruce · Apr 18, 2016 at 12:47 AM

@Fujitaka

If I understand you correctly you want to scale a current GameObject by another GameObject. Try the following (you can also modify any other properties here)

 using UnityEngine;
 using System.Collections;
 
 public class BlobManager : MonoBehaviour
 {
     public GameObject MergeBlob(GameObject originalBlob, GameObject newBlob)
     {
         Vector3 originalScale = originalBlob.transform.localeScale;
         Vector3 newScale = newBlob.transform.localeScale;
         Vector3 mergedScale = new Vector3(originalScale.x * (1 + newScale.x),
                                           originalScale.y * (1 + newScale.y),
                                           originalScale.z * (1 + newScale.z));
         originalBlob.transform.localeScale = mergedScale;
         return originalBlob;
     }
 }
Comment
Add comment · Show 6 · 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 Fujitaka · Apr 18, 2016 at 01:05 AM 0
Share

hm... that's at least a start! Not sure whether I figured that out fully, but do I understand that correctly that I have to attach that script to a separate game object (I called it simply Blob $$anonymous$$anager) or should i copy the function into the script attached to the blob prefab? And besides that... I don't see where the merging part itself is ^^'

thanks for the help!

avatar image TBruce Fujitaka · Apr 18, 2016 at 01:41 AM 0
Share

@Fujitaka

In your original question where you say you are looking to merge two GameObject's, the only thing you mention is their size in that you want to grow or scale the one GameObject by another. You were not specific in what you wanted to merge other than the scale/size.

I did however take into account the fact that you may want to merge so to speak properties from one GameObject to another with this text (you can also modify any other properties here).

To answer you other question I made the script so that it could be a standalone script and called but you can easily just copy the function and place it where you wand. I have added an update of the function I provided earlier with a new one as well as some comments

 public GameObject $$anonymous$$ergeBlob(bool additive, GameObject originalBlob, GameObject newBlob)
 {
     Vector3 originalScale = originalBlob.transform.localeScale;
     Vector3 newScale = newBlob.transform.localeScale;
     Vector3 mergedScale;
 
     if (additive)
     {
         // increase the scale of originalBlob by newBlob
         mergedScale = new Vector3(originalScale.x + newScale.x,
                                   originalScale.y + newScale.y,
                                   originalScale.z + newScale.z);
     }
     else
     {
         // increase the scale of originalBlob by multiplying newBlob * originalBlob
         mergedScale = new Vector3(originalScale.x * (1 + newScale.x),
                                   originalScale.y * (1 + newScale.y),
                                   originalScale.z * (1 + newScale.z));
     }
 
     originalBlob.transform.localeScale = mergedScale;
 
     // merge any other properties of newBlob into originalBlob here and/or
     // if newBlob and originalBlob has any component attached that you want merged
     // do it by getting the indiviual componts of each and make the necessary merges
 
 
     return originalBlob;
 }
avatar image Fujitaka TBruce · Apr 18, 2016 at 02:27 AM 0
Share

Ok, that helps me, since I can delete the smaller blob after the original blob gets bigger (to simulate that they are merging into one blob) but the part that I don't get now is, how to get them to know, when to merge together. They should merge when they are at a certain (very short) distance from each other. I guess I didn't elaborate on that enough in my original question, and I'm sorry for that. But at least I now have a way of calculating the size of the blobs that are merging, so thank you for that ^^

I suspect I'll have to try something with raycasts, to detect other blobs in close proximity, but I'm not sure how to do that... If you have a more efficient way to do that, let me know, but you already helped me a lot, so no hard feelings when I don't get an answer ^^

Thanks again, and have a nice day fine sir (or lady... I don't judge ^^)

Show more comments
Show more comments

Follow this Question

Answers Answers and Comments

55 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

checking if gameobject exists 1 Answer

How to Serialize or Save a List of GameObjects 1 Answer

Spawn objects in a row with same spacing 0 Answers

How to change the shape of gameObjects 2 Answers

Accessing values on a gameobject 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