Public Group

# Platform water.

This topic is 4056 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

For a project I'm working on, I need to figure out a way of doing 2D water that can settle into pools, and get quite a bit of depth without eating the processor too badly. I'm leaning towards a setup that handles bodies of water and jets of water differently, but can switch between the two. Bodies of water: a 2D array based setup, probably just integers since all it needs to store is "water (1)", "no water(0)", and "compressed water (2+)". Water would be distributed to adjacent grid squares based on the square with the lowest value compared to it's other neighbors. this is mainly because the goal is to get a fast, visually appealing simulation, and the normal rounding method won't work with integers. If an integer getting "shifted" in this way would get shoved off a ledge, it would get replaced with a particle for the jet setup with velocity dependent on the pressure behind it. Jets of water: Particles that are replaced with values on the above table when they settle. simple enough. Would this work? I'm aware that most of the articles on fluid dynamics for games tell you to use float or double variables, but I'm trying to implement this in such a way that it can coexist peacefully with a platform engine without slowing down too much. Any suggestions for how to do this better would be greatly appreciated.

##### Share on other sites
Are you looking for water that will fall down and over things, or just for pools of water? If it's just pools, you could probably just simulate the water surface and then find a way to determine if a point (the character) was in the bounds of the water or not. I believe storing an array will prove harder than anything. I figure using a simple little sine wave to simulate the surface (and modulating it for any contact that results in waves) would be the best way to go if you want more dynamic water.

##### Share on other sites

As for not using floats, it wouldn't be hard to convert these to using a good fixed point math datatype. However, I think any performance loss from using floats will be pretty minimal considering the might of modern machines and your relatively low CPU demands otherwise.

##### Share on other sites
Do you just want to render the water, or do you actually want to factor it in to physical simulations?

##### Share on other sites
This would be for the "flowing over things" type of water. Part of the rationale for using integers was that switch statements could be used instead of nested if statements, but if I'm just being paranoid over performance then float values might be better.

An example of what I'm trying to come up with would be similar to the fluid simulated in the "clonk" series, so the smoothed particle hydrodynamics is probably epic overkill. The idea of this is to get water that gets good enough performance to not just fill a small pond or something, but to flood the whole level.

Oh, and another reason for performance concerns is that I was trying to make each unit of water one pixel, but that might not end up being possible. I'm going to try to break the simulated water into boxes, so that the whole level isn't getting updated if someone empties a bucket or something. I'm pretty new at this, so I'm not really sure what modern machines are capable of, but I generally like to err on the side of caution.

1. 1
Rutin
24
2. 2
3. 3
JoeJ
20
4. 4
5. 5

• 9
• 46
• 41
• 23
• 13
• ### Forum Statistics

• Total Topics
631749
• Total Posts
3002031
×