Sign in to follow this  

Platform water.

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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 this post


Link to post
Share on other sites
Here is a related forum thread which might be relevant to your interests: link.

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 this post


Link to post
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.

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this