Water Bubble Physic

Updated on November 4, 2017 in [A] Other Answers
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
3 on November 3, 2017

Hello,

I’m new to Unity, still learning everything. I came from Unreal Engine so I’m still understanding the workflow. I’m making a 3D game and I need some help. My main character is a water bubble, let’s imagine that is a water bubble with some consistency, in real life a water bubble in some surface will spread, but what I want is a water bubble that has the consistency to stay a bubble but for example if I hit a edge it will divide in two bubbles and if they meet each other they will merge. I hope I make this easy to understand.

Can someone guide me on this?

Thank you very much!

  • Liked by
Reply
2 on November 3, 2017

Well, as I understand your idea, you can probably try the following:

  1. You give your main bubble a collider and enable isTrigger
  2. You give your edges on which it will split a tag
  3. You write a script for the main bubble with OnTriggerEnter() which will spawn two little bubbles you created before and destroy the main bubble. So basically like that:
public static bool isMainBubbleExisting;
private void OnTriggerEnter(Collider other)
    {
        if(other.tag == "Edge")
        {
            isMainBubbleExisting = false;
            Instantiate(tinyBubble, transform.position, transform.rotation);
            Instantiate(tinyBubble, transform.position, transform.rotation);
            Destroy(gameObject);
        }
    }

4. These tiny bubbles has also a trigger collider and a tag, so that you can give them a script too. Then do the following to merge them:

    private void OnTriggerEnter(Collider other)
    {
        if(other.tag == "TinyBubble")
        {
            //check if main bubble exists, so you don't produce more of them
            if (!mainBubbleScript.isMainBubbleExisting)
            {
                mainBubbleScript.isMainBubbleExisting = true;
                Instantiate(mainBubble, transform.position, transform.rotation);
            }
            Destroy(gameObject);
        }
    }

5. And to make all things more smootly you can add some animations before you instantiate and destroy.

on November 4, 2017

Hello,

Thank you very much for your reply! I’m still learning the Unity, and when I feel prepared I will try to start my project. If I need some help I will reply in this topic. Once again thank you very much and have an amazing weekend.

Helpful
on November 4, 2017

You’re welcome.

 

Show more replies
  • Liked by
Reply
Cancel