Floater is a simple-to-use script you can add to objects to make them float realistically in water. Floater plays well with Unity’s build in physics system, so objects that use Floater will interact realistically with other physics objects. Best of all, Floater also supports ragdolls, humanoid or any other body topology. Use Floater to create realistically floating boxes, crates, balls, chests, barrels or any other simple shape. Create ragdolls out of dead enemies, and let them float in the water.
Create more complex floating objects, like a pontoon bridge. Connect Floater to the pontoon bridge, and let Floater automatically handle the movement of the pontoons as you roll tanks across the bridge.
Tons of applications for any game featuring water and stuff that floats.
- Fast heuristic computation of sphere’s, boxes or capsules bouyancy
- Automatic computation of density, for realistic behaviour
- Automatically detects correct shape and formula to use for a given object
- Automatically handles ragdolls.
- Plays well will Unity physics, allowing for floating objects that realistically interact with other physics objects.
simple geometric shape:
Simply drag and drop the FloatingBody script on a non-kinematic rigidbody with a sphere, box or capsule collider attached. Adjust values for Water level, bouyancy and waterdrag as desired, or use the default values to get wood-like behaviour.
Drag and drop the FloatingBody script to the root of a ragdoll (for a guide on how to create a ragdoll, see here ). Set the value isRagdoll to checked, and adjust values for Water level, Bouyancy, limbs bouyancy and /or Head bouyancy as desired, or simply use the default values.
The FloatingBody component can be used on any ragdoll like object, i.e. a set of rigidbodies connected by joints. If all the objects have either a box, sphere or capsule collider, simply drag and drop the FloatingBody script to the root of the object, and set values as described in ragdoll usage above.
You could for instance build a pontoon bridge of boxes, or a rickety raft of capsules, and simply drag and drop the FloatingBody script to the root.
Floating Body component
Water level: The height of the water surface in world coordinates. If you want an object to e.g. fall over the edge of a waterfall, you can change the value of Water Level dynamically.
Bouyancy: Bouyancy is technically the density of the object / density of the fluid. The value is the fraction of the object that is submerged when the object is at rest. Set this manually to get the precise behaviour you want. If bouyancy is above 1, the object will sink.
Waterdrag: is a tweakable constant describing how much resistance the water creates. The higher the value, the more resistance the water provides.
IsRagdoll: If the script is put on the root of a ragdoll, set this value to true. FloatingBody will then treat the object as a ragdoll, and make sure it floats nicely. If the script is put on another type of object, Floating body will automatically work, and this value should be false.
Auto compute Bouyancy: If you have a rigidbody with a well defined weight already, and you want the object to float or sink as it should, based on real world physics, set this value to true: FloatingBody will then, at Start(), compute and overwrite the Bouyancy value described above. (Bouyancy is = mass of object / (volume * 1000)).
Limbs bouyancy: The limbs of a human body are generally a little less bouyant than the torso. Therefore, the limbs (arms and legs) should sink a little bit, while the torso should not. When isRagdoll is true, limbs bouyancy is used for the bouyancy of all capsule colliders in the ragdoll.
Head bouyancy: The head of a human body is a little less bouyant than the torso. When isRagdoll is true, the head bouyancy value is used for the bouyancy of all sphere colliders on the ragdoll.