Floating object

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
User avatar
Selfie
Posts: 2
Joined: Mon Apr 26, 2010 8:22 am

Floating object

Post by Selfie »

Hello :)

i'm creating a little game and i have some difficulties, and i need a little help plz ^^
i would like to make boxes with movement like if they were floating in the water (going forward and up and down)
to simulate as if they were to be carried away by the water.

the forward part is easy, for the rest i was thinking applying an impulse but its not working :/

thank you in advance ^^
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Floating object

Post by Norbo »

To simulate buoyancy, you'll need to figure out an approximation of the buoyancy force.

The equation for it is F = submergedVolume * fluidDensity * gravity; it is known as Archimedes' Principle. Fluid density is chosen arbitrarily and submerged volume can be approximated in a variety of ways. One simple way to do it is to calculate the volume of the AABB below the water plane. You then apply a linear impulse each frame to match the computed force F, impulse = F * dt.

This will produce a bobbing effect, but the object won't tumble around by itself since all of the impulses are centered on the center of mass. This keeps things speedy, especially on the Xbox.

There also exists a FluidVolume class in BEPUphysics. It computes submerged volume by sampling and can create accurate angular floating behavior, but it is expensive (it's also a little old and could use a revamp). If you're targeting the xbox and don't mind a simple approximation, I'd recommend using the manually calculated buoyancy force above.
User avatar
Selfie
Posts: 2
Joined: Mon Apr 26, 2010 8:22 am

Re: Floating object

Post by Selfie »

thank you i'll try ^^
Post Reply