← Pixel Dreamer Studio

Make a RigidBody3D float on water and settle

Push up by how much of it is under water, and slow it down by the same amount.

Buoyancy alone works like a spring with nothing to stop it, so the object keeps bouncing. In our Godot 4.7 test a 1 m crate dropped from 3 m was still bobbing 3.77 to 3.96 m from top to bottom 5 seconds later, and was fully out of the water 43% of the time. Push up by how much of it is under water and add a drag force against its velocity, scaled the same way. The crate then settled half under and moved only 0.07 m.

The code

Put this script on the floating RigidBody3D instead of a plain RigidBody3D. Set water_height to the height of your water surface and height to how tall the object is. It is made for flat water: for waves, use the wave height under the object as water_height.

extends RigidBody3D
## Makes a RigidBody3D float on flat water and settle, instead of bobbing forever.
## Set water_height to your water surface. Good for crates, barrels and debris.

@export var water_height := 0.0
@export var height := 1.0  # the body's height in meters
@export var float_strength := 2.0  # 2 = floats half under, 1 = only just floats
@export var water_drag := 3.0  # slows it down in the water, so the bobbing dies out


func _physics_process(_delta: float) -> void:
	var bottom := global_position.y - height * 0.5
	var under := clampf((water_height - bottom) / height, 0.0, 1.0)  # how much is under water, 0 to 1
	if under <= 0.0:
		return
	var g: float = ProjectSettings.get_setting("physics/3d/default_gravity")
	apply_central_force(Vector3.UP * mass * g * gravity_scale * float_strength * under)
	apply_central_force(-linear_velocity * mass * water_drag * under)

What we measured

A 1 m, 10 kg box dropped from 3 m above water at height 0, for 600 physics steps (10 seconds at 60 per second), with the default gravity and damping. We measured the last 5 seconds. Two runs with the same numbers.

Why it happens

Both common ways only ever push up. Falling in, the box builds up speed, goes deep, gets pushed back with all that speed and flies out of the water, then falls in again. The project's default linear damp of 0.1 is far too small to stop it, as the numbers above show. Water drag only takes speed away while the object is in the water, the deeper the more. Raising linear_damp instead would slow it down in the air too.

What to change

The splash when it lands: water splash when something falls in. Bubbles that stop at the surface: underwater bubbles.

Ready-made water effects: Underwater Action VFX for Godot 4 has Dive Splash, Diver Bubbles that wobble up, Air Bubble Pickup, Treasure Chest Bubbles and Hydrothermal Vent Bubbles.

Tested in Godot 4.7 with the Compatibility renderer.

Ready-made: Underwater Action VFX for Godot 4 has Dive Splash, Diver Bubbles that wobble up, Air Bubble Pickup, Treasure Chest Bubbles and Hydrothermal Vent Bubbles.

More how-tos: Water