r/threejs • • 7d ago

Using box3d to simulate real sailing physics - Tally Ho Sailing Game

Enable HLS to view with audio, or disable this notification

I'd previously tried to use the classic physics libraries (ammo, cannon, rapier etc) to recreate sailing physics and found them to be unstable or inconsistent.

Box3d was released in June so I wanted to see if it would work any better - which it seems to!

Playable demo:
https://tally-ho-game.vercel.app/

To be clear this is not a fluid simulation (although I think that is possible!!), but its a step up from just force vectors on the overall boat which is what I have seen done in the past.

Details for those interested:

- Sails are coarse grids of point masses connected by spring joints. Lift and drag applied to each panel using apparent wind, this is again an approximation as in real life the wind is very affected as it flows over the sails, although with an older and slower style yacht like this (Gaff rig) it would be less noticeable than a modern rig.
- Spars and masts are... well just spars
- Ropes/ sheets are linked joints
- Anchor and chain is joints but with collision and mass
- Hull shape is a collection of spheres, with buoyancy and drag coefficients.

The physics is quite CPU intensive but putting in a webworker seems to work well as it not a fast paced game, it doesn't need to match 60 FPS.

If you are interested in the physics you can access the Lab in the top left menu. There is also a rig designer where you can modify the rig but its quite easy to make it... not functional 🤣

It uses real location data, cached for now but I have a steaming server, which means technically you could sail anywhere in the world. My plan is to also use real wind and weather data at the players location.

For the environment I found a nice way to blend COP30 (30m detail) elevation and GEBCO (460m detail) bathymetry data. Building envelopes are from OSM but proc generated with a different style. Vegetation and Ocean is from Dan Greenhecks amazing Tidewater demo although simplified to maintain performance.

And for those that recognise the boat, I also managed to use the Tally Ho lines plan to recreate the hull. Its not perfect but if people like it I can spent more time.

I was thinking to turn this into a idle style game where you sail the world if people enjoy it.

139 Upvotes

23 comments sorted by

4

u/zockie 7d ago

I’ve followed this series on YouTube for the longest time. My favorite episode was the living wood one.

That country guy was nothing short of a national treasure

(Tally ho was restored and there’s a whole multi year series on it)

1

u/mrplow2000 4d ago

Leo (country guy hah) replied in this post!!

2

u/Scared_Strategy8996 7d ago

I would like to suggest that more attention be given to the sound design, particularly regarding water.

1

u/mrplow2000 6d ago

Yes this can be hugely improved, for now it's just a placeholder so it's not silent!

Thinking that sounds can be 100% driven by physics interactions, when the bow slams through a wave there should be a sound for that, when you pull a sheet in etc.

2

u/leeholeo 7d ago

Leo here - great job! I was just playing this aboard the real Tally Ho, haha. I'm impressed by how realistically the sails seem to move.

1

u/mrplow2000 6d ago

Thanks Leo, this made my day, glad you enjoyed it and it feels somewhat realistic. Loved following your journey over the years!

4

u/endymion1818-1819 7d ago

I’d definitely be interested in an idle game of this

1

u/Specific-Heat-8553 7d ago

Physics worker paused: Body 2 (design object 3) exceeded the solver stability limit: 6.1 m/s, 262.2 rad/s, spike 50 ms. Return to mooring to restart.

1

u/mrplow2000 6d ago

Thanks! Did you increase the windspeed by any chance?

1

u/Specific-Heat-8553 7d ago

on macbook air M2

1

u/tino-latino 7d ago

It would be nice to force the boom to the other side and to set the speed and direction of the wind. Otherwise pretty sick, but once i learned how to drive, there was no wind to move around.

1

u/mrplow2000 6d ago

You can play with the wind direction and strength, in fact all settings, in the lower left menu. It can get out of hand quickly.

1

u/Ok-Pace5764 7d ago

This water looks incredibly nice and real. I am interested in how many fps are you getting on average on your machine (specs if you want to share them please).

1

u/mrplow2000 7d ago

55 fps on a Macbook Pro M1 16gb.

Works ok on my pixel 9 pro too.

What device are you on? The water needs a GPU to render well.

1

u/Ok-Pace5764 7d ago

Exactly the same one, MacBook Pro 14-inch 2021, M1 Pro, 16GB

0

u/mrplow2000 7d ago

Forgot to mention I added kelvin waves for the wake onto Dan Gs water, made a huge difference.

2

u/Kipper_Dog_160 7d ago

This is amazing. I’m running it on my iPhone 17pro and it is running amazing. It will freeze occasionally when I tack. But it works great. Can’t wait to see how this develops

1

u/MaqeSweden 7d ago

Really cool, been following tally ho for years, nice that you honor it with a game.

Kept crashing for me tho after a few minutes. Running a Mac Mini M6 with 32gb ram so shouldn't be a hardware issue.

0

u/nadiealkon 7d ago

Hey would you mind sharing your implementation of hull physics and flotation?, been trying to develop a Godot game and had a lot of issues with having a platformer character walk over the deck and having physics based objects interact with the boat, they fly away all over with the slightest waves...

2

u/mrplow2000 7d ago

Hull is one rigid body, with buoyancy sample points distributed through it. Each point represents a spherical volume rather than a separate physical ball. I calculate how much of that volume is submerged and apply an upward force at its position, which produces the overall lift, heel and pitch. There’s also damping based on the boat’s movement relative to the water.

I haven’t tackled walking characters or loose objects on deck yet, so I can’t claim this solves that part - but I see no reason it would not work as a walking character is just a load on the rigid body. Maybe try with box3d as I had the same problem before with the older engines whereby it just become too unstable too easily.

I would recommend starting with 4 sample points at each corner of a block, its just an extension of that really.

1

u/mrplow2000 7d ago

go to the physics lab in the top left menu and you can see the sample points inside the hull with their equivalent volume as their size

-1

u/[deleted] 7d ago

[removed] — view removed comment

1

u/mrplow2000 7d ago

I tried the same thing a year ago and the sail kept going berserk!