I have a Terrain scene with a water object in it. A Lake, and I want to prevent the Player from going into the water. I have have tried a few things but no real success as yet. How can I achieve this?
Do you mean walking on the water or do you mean stop before you enter the water? Your question is a little vague, but I’ll try to answer the question.
- If you want to walk on the surface of the water, simply put a collider (of a box, sphere, or mesh) on the water game object. Now your character can walk on water.
- You can make a border, or invisible wall around the bodies of water. This can be done by making many empties (game objects that have no components) and adding box colliders (or another collider) and placing them around your water edges to block the player.
I hope this helps!
You could make a model in you 3D modeling program, import it into unity and make it into a custom collider (using a mesh collider component). This will give you that exact fit you want. Be careful though, as this will make it difficult to change if you decide to move your water, or your terrain.
There is a way to make your player stop when touching the water, but getting out of the water could be a problem. That’s why I suggest colliders. I bet there is some fancy way of how to do it out there using scripting, but colliders are easier and have less bugs.
Add A Box collider to the Water and in the inspector, edit the y size so that it is really really big and then that should stop you.
‘Add A Box collider to the Water and in the inspector, edit the y size so that it is really really big and then that should stop you’.
That doesn’t work because the collider just encroaches up the Terrain.
Yes I need to prevent the Player from entering the water. Making boxes around the shoreline is not so effective because of the irregularity of the shoreline.