Objects submerged in FluidVolumes

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Dep
Posts: 1
Joined: Sat Jan 24, 2015 12:47 pm

Objects submerged in FluidVolumes

Post by Dep »

Hello

I am writing a game where players can control a few vehicles. Most of them are water based. Submarines, boats, & aircraft carriers to name a few. I have done some testing with applying impulses to my vehicles for control but it was a bit clunky. I have a few basic questions.

How would I steer say a boat in a FluidVolume?
How would I allow a submarine to surface and dive? I did try changing the mass but this felt like a bad way to accomplish my goal.
Can the FluidVolume have waves to simulate a rough sea?
Can I make a FluidVolume an infinite plane?
If I did make the FluidVolume an infinite plane could a static mesh be placed in the middle of it to simulate land?

Thank you.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Objects submerged in FluidVolumes

Post by Norbo »

How would I steer say a boat in a FluidVolume?
There's quite a few options depending on the type of boat and what kind of control you want. Most of them will involve some method of fighting against sideways drift.

The simplest method of fighting sideways drift is to measure the sideways velocity and subtract it out. The dot product of a direction and the velocity gives the velocity in that direction, so to eliminate all sideways drift:

Code: Select all

entity.LinearVelocity -= entity.OrientationMatrix.Right * Vector3.Dot(entity.OrientationMatrix.Right, entity.LinearVelocity);
Similar effects could also be accomplished by using a deeper level of fidelity. As a fairly extreme example, you could compute an approximation of drag against the hull and rudder. The engine doesn't come with specific helpers for this, but it all boils down to changes in velocity in the end.

For forward and back motion, a simple approximation is to apply impulses in the forward and back directions. To limit the speed, either apply a drag force or explicitly clamp the speed that the acceleration is allowed to achieve. To explicitly clamp it, measure the current speed using the dot product like before and use it to limit the acceleration. Turning can work similarly; dot(direction, angularVelocity) gives angular velocity around that direction.
How would I allow a submarine to surface and dive? I did try changing the mass but this felt like a bad way to accomplish my goal.
The simplest approach would be to give it neutral buoyancy and then to apply up and down impulses. For a somewhat more physical approach that doesn't require modifying the entity itself, add an entry to the FluidVolume.DensityMultipliers dictionary.
Can the FluidVolume have waves to simulate a rough sea?
Not at the moment. The FluidVolume could be modified to support it, though it would take some effort.

I have some plans to add in some form of waves eventually (along with a general FluidVolume rewrite; it's extremely old), but there's a lot of stuff that needs to get done first. I would not be surprised if it took until 2016 for me to get around to it.
Can I make a FluidVolume an infinite plane?
The surface could be defined as one really big triangle, which could approximate infinity.

You could also modify the FluidVolume directly. This would involve setting the bounding box to basically-infinite (float.MaxValue along horizontal extents), removing the filter against surfaceTriangles in the AnalyzeEntry function, and setting the surfaceTransform appropriately (its position needs to be aligned with the surface of the water).
If I did make the FluidVolume an infinite plane could a static mesh be placed in the middle of it to simulate land?
Yup!
Post Reply