this post was submitted on 25 Sep 2023
11 points (100.0% liked)

Game Development

3476 readers
3 users here now

Welcome to the game development community! This is a place to talk about and post anything related to the field of game development.

Community Wiki

founded 1 year ago
MODERATORS
 

I'm working on a simulation toy, and I want to model wind on my world/levels.

I'm currently using playrho (a box2d fork) with gravity set to 0 to model a top down view.

I assume the wind will be represented as a vector field. But I'm unsure what method to use to get this field.

Could someone point me in the right direction? Should I be looking at the navier-stokes equation? Does anybody know of any relevant tutorials?

Thanks in advance!

top 5 comments
sorted by: hot top controversial new old
[–] [email protected] 5 points 1 year ago

Well, firstly you need to decide how accurate you want your wind modeling to be, but generally, the less complicated an equation you can use for your desired level of accuracy, the better. It'll end up being a vector field, but I would probably make simple rules for how the wind interacts with objects in a given tile and the tiles around it, rather than trying to model fluid dynamics precisely.

Another approach might be a ray-tracing style approach, where the rays can bounce off object geometry and lose some momentum, objects can respond to ray impacts and gain momentum, and you do some vector math to figure out what happens when rays and moving objects intersect.

The exact approach depends on the specifics of your game, and the "right" answer might be neither of these.

[–] [email protected] 4 points 1 year ago

If you want to write it as a fluid sim, you can take a look at "Real-Time Fluid Dynamics for Games" by Jos Stam.

There was also a series of articles by Michael J. Gourlay on Intel's website (maybe about a decade ago?) called "Fluid Simulation for Video Games". I'm having trouble finding an index of it, but individual PDFs for some of the entries show up in Google -- you might need to go digging around archive.org for that one, but it had a lot of interesting info in it. I think there were somewhere around 20-ish parts and some of the later entries discussed things like modeling heat.

That might be more detailed than what you're interested in, though; the rabbit hole on this subject goes deep...

[–] Temporalin 3 points 1 year ago

I forgot most of my simulation subject, but we did a 2D particle simulator and yes, you will need Navier-Stokes if you want the effect to be physically correct. You will need to solve a numerical problem each frame to compute turbulences. Wind is a force with a source that will propagate depending on its parameters (like viscosity)

If you don't implement that, you won't be able to implement things like walls that block wind and such, which I guess is something you might had in mind. Also, having a changing environment is probably pretty hard, so prepare yourself.

I just took a look at the source code of The Powder Toy, and the class Air (src/simulation/Air.hpp/cpp) seems to implement what you need. Sadly it is not very well documented, so you'd have to work out the relation between code and physical formulation.

Sometimes physically incorrect simulations are easier to implement, have lighter computations, give the designer more control of the game, and makes the player able to better predict how the game will behave and have more fun.

[–] [email protected] 3 points 1 year ago* (last edited 1 year ago)

Air is a compressible fluid, so ultimately you'll need Navier-Stokes, but actually figuring out how to translate those equations into code is infamously annoying, so definitely check out an existing solution instead of trying to implement from the equations. Foster & Metaxas is an old a grid-based solution. Theirs is designed for incompressible fluids (water), but I think it should be fine if you raise β₀.

There's a lot of math in the paper, but it's easier to implement than it looks (each step, run [2] on every cell once, then run [6] [7] [8] on every cell ~6 times), and it's mostly just transcribing equations. It's super fiddly though, just incredibly fiddly, expect to have to spend a lot of time debugging.

There are probably suitable simpler solutions too though, so definitely spend some time searching for them (or just copyable implementations of Foster & Metaxas) before diving into that.

[–] [email protected] 1 points 1 year ago* (last edited 1 year ago)

Adding to the other ideas here.

You could use a simpler analytical approach by overlapping a bunch of perlin noise functions. I've used this for pushing around gpu side particles and it looks sweet.

Yet another one is to go with a bunch of spheres that move around the level using whatever logic you want. They could even bounce off walls in their own physics world or collision layer. You can overlap their influences. I've used this for animating tree wind and it looked amazing. You can easily simulate gusts.

You can think of this as a simple way to localize influence.

You could even use a whole lot of them and combine them with perlin noise to define their volumes, which works a lot like volumetric clouds.

Happy to help further.