Skip to main content
GameDev.net gamedev.net
🔒 Locked

Detecting water?

Started by Butabee Feb 5, 2010 at 2:08 AM 8 replies 1.8k views
Original Post
Butabee
Butabee
I was wondering how to detect if a player is in water, and not just cubes of water but different shapes of water. I'm in the process of making a game with a sphere world so I can't just make the water a flat plane or cube.
elizer777
elizer777
Well two solutions come to mind (probably others):

- Cheap way, and if your water is leveled, is just check distance player has from the center of the globe. So water would be from 0 to 10 units from the center. As long as player is above threshold, then player != wet (example).

- Next way, if ur water is not uniform (can be situated in different heights, pockets for example), then just place collision boxes that approximate its volume.
Butabee
Butabee
I'm using OgreNewt for my collisions so maybe I can just detect it with a per-polygon collision. I just don't know how to make it so the collision doesn't keep the player from going inside the water. I think if I detected the collision this way, they would just stay on the surface of the water.
Krohm
Krohm
Most of the time water is implemented as "broken ground", the engine likely sets some form of underWater=true as a result of collision response with arbitrary geometry by polling surface properties. Note this is very high-abstraction and could actually mean basically everything...
Previously "Krohm"
Hodgman
Hodgman
How do you represent the water in the first place?
Butabee
Butabee
I think what I'll do is what Namar777 said. Detect how far the player is from the center of the globe and if they're too close they're in water. And I'll use collision boxes for small bodies of water.

I initially didn't want to do this because I wanted to have underground areas, but I decided that I'll just have the underground areas on higher ground.

Thanks guys.
Xgkkp
Xgkkp
Quote:
Original post by ButabeeI initially didn't want to do this because I wanted to have underground areas, but I decided that I'll just have the underground areas on higher ground.


Couldn't you just define a region on the sphere where this test isn't made?
Concentrate
Concentrate
Or make the bounding box for the region that the water occupies, where the height
of the box is the maximum height of the water at that time and check if there
is a collision between the box and the object.
Lord_Evil
Lord_Evil
In general physics engines provide some form of trigger, i.e. a collision volume that does result in a non-physics response, i.e. the collision is just reported and not further handled by the physics engine.

Thus you could make your water a physics volume or provide a water "surface" volume which triggers an enter/leave water action.

Hope that helps.
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
Butabee
Butabee
Quote:
Original post by Lord_Evil
In general physics engines provide some form of trigger, i.e. a collision volume that does result in a non-physics response, i.e. the collision is just reported and not further handled by the physics engine.

Thus you could make your water a physics volume or provide a water "surface" volume which triggers an enter/leave water action.

Hope that helps.


I just found out the physics engine I'm using can do this. So I can have any shape of water I want really.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.