- Home /
How would I detect water level at the player's position?
I have an area trigger currently, that occupies the same space as the body of water. When the player enters the area trigger, an event is fired which triggers an underwater effect.
The problem with this approach is that it is innacurate when the water level is actively changing due to waves generated by gerstner displace.
My question is what would be the most efficient way to actively track the water level at the player's position and trigger the underwater effect?
Solutions I have thought of so far:
-Use a mesh collider and update the mesh real time based on the water mesh (sounds incredibly inefficient)
-Scrap gerstner displace and keep the water at a predictable level that the area trigger can accurately account for
-Check the mesh vertices closest the player for height and do a check versus the player height (also possibly inefficient)
I'd love to hear the community's thoughts on this, source engine seemed to figure this out ages ago on pretty tame pc's.
Have you considered creating your water surface with a different algorithm? A perlin noise heightmap would probably be easier to work with... $$anonymous$$ight not look as nice tho. I suggest Perlin noise because there is a generator available for free at the asset store. http://u3d.as/content/unity-technologies/procedural-examples/3zu
I want to know it too, it seems to be a interesting answer.
I don't have any solution, but I am looking for a way to support the exact same thing on my side. In order to stimulate things a bit more on this problem, and for the good of the whole community, I am personnally offering compensation to the person who can give a working and efficient (framerate) answer. Some things just need to be done in order for Unity to grow faster.
One thing I can recommend to anybody wanting an answer to this: don't wait for it to happen. Ins$$anonymous$$d, there are some alternate ways to bypass this limitation, like forcing your camera location to move up or down via program$$anonymous$$g when the camera is moved within the $$anonymous$$imum and maximum amplitude of Gerstner waves. Or in another way that doesn't modify your camera transform at all, just make a white flash appearing over everything else. This will simulate transition from surface to underwater, and can also basically simulate some water foam. This is an easy and straight-forward alternate solution that will work both in Unity Pro and Unity Free.
Just picked this up in this thread. Will post progress here too.
Answer by Jeff-Kesselman · Jun 02, 2014 at 01:15 AM
I would put the water on its own layer and do a ray-cast down from the center of the player.
This is assuming your mesh collider properly tracks your water deformation.
Answer by Fappp · Apr 26, 2015 at 09:36 AM
Just found this, definetely not my work or anything! But seems like a very graceful solution for water at first glance :)
Your answer
Follow this Question
Related Questions
How to change scenes by touching objects? 2 Answers
Non-Convex Mesh Collider triangle limit - is it more than 255? 0 Answers
Changing Mesh and Mesh Collider of an Object 0 Answers
Find all triangles inside given bounds 1 Answer
Weird bounce on collision with perfectly aligned (generated) meshes for fast object 3 Answers