Hey, Unity Developers! What I have here is a package of simple scripts that (fairly realistically) simulate a few aspects of aquaphysics (or water physics) like floating. The package also contains a script that will update an object’s drag and angular drag when cloning an object directly (the “DragUpdater” script has more info on this, so look at it if this doesn’t make sense) or trying to make its drag unchangeable (for the most part). I’ve tested it continually and after maybe 3 hours of work it looks pretty good! The ReadMe has a tiny bit of info, but most of how the scripts work is commented in on the scripts themselves.
The scripts can be added to any object through the project view, or they are in the “Physics” tab in the “Component” menu.
Note: I don’t recommend adding both the “DragUpdater” and “BuoyantObject” scripts to a single object, so try not to directly clone a buoyant object.
Version 1.1 includes a test scene (provided by bigkahuna) and an update to the supporter script adding a gizmo. (Note on the gizmo: its y center is based at y = 0, and extends up and down y as specified by waterLevel, so if you have a negative waterLevel, the actual plane that the objects float on is the lower bound)
What do you mean? Is it not loading correctly into Unity? I can post the scripts if you’d like, there’s only three and they’re tiny. Do you think that would work?
Attach the “Buoyancy Supporter” component to the object that is serving as water, and the “Buoyant Object” component to an object that can float in the water object
He wants physics effects for his river surfer: I’m guessing white water and waves and making the flow of the river look good. Add it to your Aqua Effects if you help him.
The scripts can be accessed directly from the project view in <Assets / Aquaphysics> or the component menu <Component / Physics / Aquaphysics>. Be sure to look at the ReadMe and the comments in the scripts- they have some info that will help. If you have any more questions then email me at orbitusii@gmail.com.
Thanks, goat! I’ll be sure to do that. I’m not the best with scripting, but I think I may be able to figure something out.
Hm hm… I think the issue may be that your object’s mass needs to be >1…
What are the components you have on the object you want to float and the water you want it to float in? I also need the specifics on the rigidbody of the object you want to float, the buoyancy supporter, and the water’s collider / trigger. If I can find the problem in these then I should be able to figure it out.
@Cyrus: That would certainly make sense. I slept on it and determined that the most likely cause of an issue would be the water level not being at the right value. If you have the water object at y = 1, then the water level needs to be at 0 or at most 0.5 (it’s a global value).
@bigkahuna: I found the problems with your setup. 1- the trigger on your plane needs to be a box collider set below the plane’s surface (y center at -5, y size at 10 are just some arbitrary values i picked), and the water level needs to be about -0.25 (best value I found). I also upped the mass on the cube to 10 so it responds to the drag part of the supporter’s coding better. Here’s the test scene with those fixes: 1065992–39643–$aquaTestFixed.unitypackage (6.28 KB)
Also, an update on the status of the package: I will be updating it so that the buoyant objects will appear to bob up and down as if affected by waves (this will apply to the BuoyancySupporter). That should be uploaded sometime today.
Okej, well, there is one problem with making it a box collider. If you make water like a swimming pool your package workes perfect, but when you are using it on Plane there is a problem I think.
That’s kind of the thing with triggers: in order for them to be useful when applying force, you need room for the object that entered the trigger to adjust to the new force it’s undergoing. The purpose of the plane is to make it appear as though there is a water surface, but planes have no depth (no inertial adjustment space), so a box collider is needed. If you want to make an ocean that extends a long way in any direction, you’d simply need a box collider that is very deep and wide / long enough to encompass the useable area of the ocean.
You can’t really turn a flying plane on a dime, and the same applies (indirectly) to floating objects. I suppose you could tweak the script to change the physics on the rigidbody when it enters the trigger, but they would be reverted once it passes through the plane (no depth again, see?)