- Home /
Make the player not able to walk in/on water
Hi, so basically I just need help coming up with a way to make it so that the player cannot walk in water of strange shapes, such as seen in this picture:
As you can see, the water is not a regular shape, so placing a bunch of empty gameobjects with colliders wouldn't be a very efficient solution. I tried exporting the terrain to blender and making a shape around the pond and giving that a collider, but that was extremely tedious, inaccurate, and would be an enourmous pain to implement for every source of water.
Does anyone have any better solutions? Any ideas would be appreciated, thanks.
To clarify: I dont want the player to be able to make contact with the water. I want them to be able to walk up to the water, but not go in it.
EDIT:
When I say the colliders wouldn't be an efficient solution, I mostly mean it would be difficult to get the exact outline of the water, and it would take a very long time to accomplish. Not necessarily resource efficient, but it's not time efficient or practal.
Confused - you say you don't want them to walk on water but then you talk about adding colliders and stuff which implies you do.
Try add/remove mesh collider
I dont want the player walking in the water at all. When im talking about colliders I mean having them around the water so the player cant walk into the water at all. I guess I should clarify that better
mm.. i got confused little bit too ,but: If you want your player to NOT sink, when stepping on the water, just add a simple cube collider at the water plate. it will be little bit lower than the rest of the terrain anyway.
Or if you want your player to NOT be able to go in the area at all, where, there's water, then i think mesh collider will be the most accurate, and i don't see what's so much of work, that you have to do. I woud do simple mesh colliders, that are pretty low poly, wrapped around the ponds...
The problem is that the water itself isnt the shape of the pond, its one big circular plane underneath the terrain. So adding a mesh collider isnt so simple because I need to get the exact shape of the pond into a modelling program...
Answer by getyour411 · May 05, 2014 at 11:59 PM
Try this: Take the water shape into Blender, grab the top face and extrude it up, create a new object from that and import it back into Unity. Place it above the water in scene and turn off it's mesh renderer turn on it's mesh collider
I cant just grab the water shape face though because the water itself is just a large plane stretched under the terrain, and its just a circle.
So it's a plane or it's a circle? Either way I guess, if that's the case why not just use a primite cube or sphere in Unity scaled to the same size (except more Y/height) with it's mesh renderer off and mesh collider on
Answer by Clet_ · May 06, 2014 at 12:00 AM
Calculating collisions with a bunch of simple BoxCollider isn't very stressing CPU-wise. Just make a rough shape around the water and let the Physic handle the collisions.
It seems like you got caughtin the too-early optimization trap.
So far it lookes like that might be llthe best option, but placing a bunch of colliders around every single water source just seems a little tedius and not so efficient time-wise. I would prefer handling it through code somehow, if thats possible
Answer by Jeff-Kesselman · May 06, 2014 at 12:32 AM
As others say, its not at all clear that a collider will be less efficient. However there are a few ways you could cheat this.
Very often, water is done as a plane below the walked on terrain. If thats true in this case then the terrain that is walkable will always be at a higher Y coordinate.
SO you could cast a ray from the character down to see if the first collision is at water level.
Another thing you could do is gave the water plane or planes their own tag. Then you cast a ray down and see iof the first thing it hits has the water tag.
Finally, if the water is NOT under other areas but only where it shows, you could put it on a separate layer and cast a ray just to see if it hits that layer at all. That would be significantly more efficient then the other ray casts.
Your answer
![](https://koobas.hobune.stream/wayback/20220613144331im_/https://answers.unity.com/themes/thub/images/avi.jpg)