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.
- A fixed upward force of twice its weight while its center is under water: the center went from -1.83 to 1.94 m, a bob of 3.77 m, and the box was fully out of the water for 128 of 300 steps.
- A force by how much of it is under water, with no drag: from -1.90 to 2.06 m, a bob of 3.96 m, fully out of the water for 128 of 300 steps.
- The script: it moved 0.07 m from top to bottom, never left the water, and its center was at 0.00 after 10 seconds: half under, as
float_strength2 should give.
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
float_strength: 2 floats half under, 1.25 floats mostly under, below 1 it sinks.water_drag: higher settles faster and feels thicker. Around 3 settles a crate in a few seconds.height: the object's height in meters, so it knows how much of it is under.
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.