Difference between revisions of "Objects Floating in Water"
(Created page with "''Written by Geep, 2019'' Entities found in the “Movables” folder will float dynamically in water if their calculated density is light enough. But there are issues. == A...")
|Line 52:||Line 52:|
Latest revision as of 00:25, 17 July 2019
Written by Geep, 2019
Entities found in the “Movables” folder will float dynamically in water if their calculated density is light enough. But there are issues.
Adjust the “Mass”, Ignore “Density”
To control floating and underwater behavior (detailed below), you may wish to inspect and override the inherited “mass” spawnarg value. If a mass value is defined - and it always is if you use a standard moveable class - then the “density” spawnarg is algorithmically ignored… so you can ignore it too.
Remember that the mass of an object can affect non-water aspects of game play.
Desired Initial Placement of an Object
This restates general considerations when placing a Moveable in the map, but in a water context.
In the Water, but Above the Sea Floor. By “sea floor”, we just mean the first solid object encountered directly below the object. Place the movable object where you wish (below, at, or slightly above the water surface), and set its “nodrop” spawnarg to “1”. On worldspawn, it will stay where you placed it, awaiting activation by the player.
On the Sea Floor. Like the above, but make sure nodrop = 0 (the usual default). On worldspawn, the movable will move immediately to the sea floor (without special effects), awaiting activation by the player.
Far Above the Water. If the object is placed far above the water or any other floor, it just hangs there (awaiting player activation), no matter the nodrop value. If the player is swimming, the object will be out of reach.
Getting the Placed Object to Activate
Unfortunately, the object will not rise off the sea floor, or if at the surface, begin bobbing, until after the player activates it by bumping and/or frobbing it.
Clever game design may get around this, e.g., in the case of a floating rowboat, spawning the player directly into it.
[Is there a way to activate objects by triggers/scripting?]
Plausible Behaviors When First Activated
Objects initially placed above the water surface or higher in the water than they would normally float may trigger splash sound and visual effects, and plunge below the surface (before arising if buoyant). Similarly, initially underwater objects that are highly buoyant may pop above the surface, with effects.
As in real life, the presence and extent of such behaviors is presumably influenced by the momentum at surface penetration. But the engine likely scants object shape and orientation.
Effect of Mass on Buoyancy and Floating Behavior
The mass divided by the calculated (or estimated) volume gives a calculated density, which affects how high in the water an object sits and (along with mass) how vigorous any bobbing and roll-about may be.
The following summary table gives rules of thumb, based on experiments detailed further below. For box-shaped objects it is possible for both you and the physics engine to easily calculate the volume, and from that (given the mass) the density. For other shapes, the engine likely deploys shortcut estimates (perhaps using the collision model) with ad-hoc fudge factors. Rather than attempt to mimic that (or guesstimate appropriate volumes for corpses or complex prefabs), you might use the table as follows:
- Observe the object’s floating behavior, and from that, impute its approximate density.
- Compare that to the desired behavior, and scale the mass value proportionally.
- Iterate until happy.
|Estimated Density||Underwater: Sink (⇓) or Rise (⇑)||Float Behavior at Surface|