• 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 Enverhan · Dec 09, 2021 at 05:59 PM · physics

Spawning objects overlapping and pushing each other

Hey guys, I'm trying to create a game which guys holding the balloons and balloons spawning every few seconds. My problem is without rigidbody balloons I spawn overlapping each other and with rigidbodies balloons pushing each other. I want spawning ballons to squeeze each other and look like bouquet of flowers. My spawn code is below. Thanks for your help.

 public class Balloon : MonoBehaviour
 {
     public List<GameObject> targets;
     private GameObject player;
     public float Timer = 2;
     // Start is called before the first frame update
     void Start()
     {
         player = GameObject.Find("Player");
 
 
     }
 
     // Update is called once per frame
     private void Update()
     {
         Timer -= Time.deltaTime;
         if (Timer <= 0f)
         {
             StartCoroutine(SpawnTarget());
             Timer = 2f;
         }
     }
 
     IEnumerator SpawnTarget()
     {
         yield return new WaitForSeconds(Random.Range(1, 1.5f));
         int index = Random.Range(0, targets.Count);
         GameObject newBalloons= Instantiate(targets[index], new Vector3 (transform.position.x,(transform.position.y+0.8f),transform.position.z), Quaternion.identity, transform) as GameObject;
         newBalloons.transform.parent = transform;
     }
 }
 
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Enverhan · Dec 10, 2021 at 10:32 AM

Yeah I want my character to hold ballons from bottom of the stick/rope. Should I use hinge joint for that or is there some other way ?

Comment
Add comment · Show 2 · 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 metalted · Dec 10, 2021 at 11:26 AM 0
Share

Well it all depends on if you want to use physics or not. If yes then you probably want to use character joints or configurable joints, because those will act like ball and socket joints. Using hinge joints will make the balloons only pivot on a single axis, like a door. If you don't need any physics, you could spawn the balloons in the position they need to be, which will require some math to calculate the right position, which could get complicated. A very easy solution to this, when you don't need physics and you have a finite amount of balloons, you could also just make the entire balloon structure by hand, with each balloon&string being a seperate gameobject. At the start, you disable all the gameobjects and enable them one by one when needed.

avatar image Enverhan · Dec 10, 2021 at 01:09 PM 0
Share

Closest to what I want to do is balloons in the below link. I did tinkered a little bit with character joint but couldn't make it work. https://imgur.com/a/VYzRoO2

avatar image
0

Answer by metalted · Dec 09, 2021 at 08:56 PM

Im guessing you want them to act like helium balloons. You hold multiple helium balloons on string and they will clump together above your head. Because this is basically a physics simulation, you are going to need Rigidbodies. You could of course fake it by just giving the balloon a certain position, in that case you don't need rigidbodies but they will not interact with each other.


The code you are using now, does exactly what it is supposed to do. But if you want your balloons to act balloon-like you are either going to have to fake it (animations, translations that kinda stuff) or make a structure that will be similar to the balloons. For instance, you could create a ball joint at the hand, with a string (read stick) attached to that. Then you add another ball joint at the end of the string and add your balloon there. Helium balloons have buoyancy, so you just add a little bit of force continuously upwards. The balloons will hinge on the hand so will rotate upwards, colliding with each other above.


Thought it would be best to add an example so you can see how it would look. In the below picture you see a hand (cube). The balloons are all the same, at the little spheres there are joints. Bottom spheres are connected to the hand, top spheres connect the strings to the balloons. The balloons themselves have a script attached to them, adding a little bit of force upwards in the update function. The top picture is the object as is, bottom picture is during Play Mode. The effect of this is also, that if you move the hand, the balloons will also interact with the movement.

alt text


This is of course just a ball on a stick, so it will act like a ball on a stick. It's all up to you to make it as realistic as you want, but it sure looks like a bouquet of balloons to me. (As long as you dont move it, but let's not talk about that...)


a05fd3f5-6513-4ff6-bf79-baad32488dd0.jpg (95.5 kB)
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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

209 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 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 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 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

2D 360 degress platformer example needed 0 Answers

Networked Physics 0 Answers

How do I make a lander? 0 Answers

Unity 2D Car Side Scroller question. 1 Answer

object goes through another object error 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