I think I’ve got the forces calculated right.
Now my problem is, how can I exert them to my rigidbody (box that will float on the water surface), in a way that can imitate buoyancy?
I’m not quite sure, how exactly the “drag” works, but currently what happens is that my cube is just jumping on the top of the mesh and doesn’t sink at all.
Am I going in the right way?
Or I don’t use the API correctly?
Sorry for the bad english.
I think you’re also missing a step with the way the volume is being used in the CalculateBuoyancy() function. I think you need to work out the submerged volume rather than applying the entire volume. When the object first hits the water it’ll not be entirely submerged so it won’t displace it’s entire volume’s worth of water.
1 Cubic Foot is 7.48 galons, so I was converting it from cubic feet to galons for the density formula, but I figured that I just need the forces so I coppied the volume formula for my body… (I removed the 7.48 now.)
You’re right for the submerged volume… I’ll think about this now, but currently I have no idea how to track, how much of my object “sank” underwater.
I was dividing the volume and the mass by 1000, but then I thought that I don’t need to convert them like that, because my object just kept on sinking. (Don’t know if I’m correct here)
Ok, I figured that to calculate the submerged volume I need the volume of the object (v) the density of the water (wd) and the density of the cube (d).
I hope everything is how it should be in the calculations…
The problem now is that my Cube is constantly jumping out of the water and diving in with the same distance.
Do I add the forces correctly?
I’m new to unity, and I’m not too sure how to use the “AddForce” method and the “drag” members…
Update:
I realised that when I give more mass to my cube, it floats better than when I give it less mass.
So I saw how many mistakes I’ve let in my formulas…
The forces of gravity and buoyancy are calculated like: Density = mass / volume and not Density = mass * volume (Sleep before you code! )
The next thing I realised is that I’m multiplying my forces by the same direction of the gravity acceleration.
Assuming what is written in the link I’ve posted we have: Force of gravity = mass of body * gravity; // gravity = - 9.8 m/s/s for downwards Buoyancy force = body volume * (-gravity); // - gravity = + 9.8 m/s/s for upwards
Then I combine them to figure out the net force.
I am calculating my submerged volume by in the end I guess I don’t really need it. I use my full body volume because that’s how much water is going to be displaced.
In the end my box dives in the “water”, and then when it pops up above the water surface it just keeps up on bouncing there.
I can feel that I’m pretty close, but I still can’t figure out how to add the forces on the rigidbody object…