Skip to main content

LiquidGravity

A class in Root.Township, Alta.Liquid.

Simulates which way a liquid surface points as its container moves and tips, with some sloshing. LiquidSurfaceVisual uses one. Plain class, client visuals.

Constructors​

MemberWhat it is
LiquidGravity(Transform relativeTo)Creates a LiquidGravity from relativeTo.

Fields​

8 private and internal fields
MemberWhat it is
private int disableFramesFrames left to skip in Update. Reset by ResetDisableFrames or Reset.
private const int DisableFramesWhileStationaryNumber of frames (30) Update skips after the liquid's up direction stops changing.
private Vector3 localUpThe liquid's up direction in the container's local space, kept between frames.
private Vector3 oldPositionContainer position last frame, used to push the liquid when the container moves.
private Transform transformThe container transform the liquid is simulated in.
private float velocityCurrent swing speed of the liquid's up direction, in degrees per second.
private Vector3 velocityAxisAxis the liquid's up direction is swinging around.
private Vector3 worldUpBacking field for WorldUp, the simulated up direction in world space.

Properties​

MemberWhat it is
float GravityMultiplier { get; set; }How strongly gravity pulls the surface back level.
float MaximumVelocity { get; set; }Cap on how fast the surface can swing, in degrees per second.
float MovementMultiplier { get; set; }How much moving the container tilts the surface.
float Tip { get; private set; }Minus the local up's height: above 0 once the surface points below the container's horizontal.
float TippingThreshold { get; set; }Tip value where TippingValue starts rising above 0.
float TippingValue { get; private set; }0 to 1, how far Tip is between TippingThreshold and fully upside down.
float VelocityDrag { get; set; }How quickly sloshing dies down.
float VisualTipLimit { get; set; }Limit on Tip for the drawn surface, so it does not tip past this.
Vector3 VisualUp { get; private set; }Surface up direction to draw, clamped by VisualTipLimit.
Vector3 WorldUp { get; }Simulated surface up direction in world space.

Methods​

MemberWhat it is
void Reset()Levels the surface and stops all motion.
void ResetDisableFrames()Wakes the simulation up if it went idle.
bool Update(float deltaTime)Steps the simulation. Returns false while idle (it sleeps 30 frames after the surface stops moving).

Used in​

Members of other types that take, return or hold a LiquidGravity: