• 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
10
Question by Phil 3 · Feb 19, 2010 at 04:57 PM · physicswater

How can I implement physics objects which float in water?

I hope this is the right place for my question! I would like to know if the following is possible using the Unity engine:

The scenario is a rising pool of water.

On the water are floating objects, like crates (some are already floating on the surface, others fall into the water from above).

As the water is rising, I want the player (3rd person) to be able to jump from crate to crate, with the crates responding to the impact, but staying afloat.

I would like the crates to be affected by other NPCs or forces in the world, like fish or water shooting out of the player's Super Soaker gun.

Does any of this sound possible? Any answers greatly appreciated!

Comment
Add comment · Show 1
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 Proclyon · Nov 18, 2010 at 02:42 PM 0
Share

These are the questions that really demonstrate the use of the UnityAnswers site! Definatly a Fav.

3 Replies

· Add your reply
  • Sort: 
avatar image
8
Best Answer

Answer by duck · Feb 19, 2010 at 05:06 PM

Yep, it's certainly possible (I have done this), although the physics of objects floating in water isn't built-in to unity's physics engine. You have to apply the forces to keep objects afloat yourself, based on how much of the object is underwater - however it's not as simple as that might first sound.

You can't just apply an upwards force based on how far underwater the object is, because that doesn't take into account that an object will attempt to lie flat based on its geometry.

I implemented buoyancy by pre-calculating a sort of volumetric grid of points that are inside the volume of the floating object, giving a sort of low-res representation of the volume of the object.

Then, when updating, I was checking how many of the volume-points are below the waterlevel. The more that were below the waterlevel, the harder the upwards force on the object. However, the point at which the force should be applied also has to be calculated, since if one end of your object is dipping further down in the water, that end gets pushed up harder.

The way I solved this was to average the position of only those volume-points which are below-waterlevel, and then use that average position as the point at which to apply the upwards buoyancy force.

This upwards force was also multiplied by a factor which determined how buoyant the object should be. This made some objects only float with a small portion above water, while very buoyant objects almost sit entirely on top of the water.

Once this was working, I was able to make floating platforms which supported my player character, and even bobbed realistically if you jumped up and down on a corner!

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 Phil 3 · Feb 19, 2010 at 09:19 PM 0
Share

Sounds like a very workable solution though I am sure it may take me some time to implement. Thank you for the answer!

avatar image duck ♦♦ · Mar 31, 2010 at 07:34 PM 0
Share

How are you getting on? did you manage it?

avatar image Proclyon · Nov 18, 2010 at 02:39 PM 0
Share

Your solution is incredibly ingenious! I am impressed!

avatar image
4

Answer by Sebas · Feb 19, 2010 at 09:54 PM

Check these two forums threads (Buoyancy1, Buoyancy2). They contain examples of buoyancy scripts which might get you started implementing what Duck suggested.

Comment
Add comment · Show 1 · 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 Ash-Blue · Aug 22, 2014 at 07:10 AM 0
Share

Wish these scripts were still up, both links are missing.

avatar image
0

Answer by SavaTim · Jun 12, 2019 at 11:19 PM

Look This https://youtu.be/W7tur5kpy6I

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

1 Person is following this question.

avatar image

Related Questions

Simulate Large ocean with player built models 0 Answers

How to do particle collision 2 Answers

How do I simulate a tsunami wave? 6 Answers

Bouyancy timing issue 0 Answers

Unity3D Water Bending with Physics 3 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