How to prevent Character Controller from falling of the edge?

As mention above, is there a way to prevent the character controller from walking to it’s death if there is no more ground to walk?

I have find a similar question as posted here:

But i have no idea on how to use it to my advantage. Can anyone be kind enough to advice me on that?

to do it in script, I would first make a raycast a short distance in front of you pointing downwards. if the ray returns a false(meaning it has hit no colider) then ignore player forward input key. That way they cant go over the edge.

the easy way is to make a cube into a wall and where you can change the cubes texture or color(sorry i forgot what its called)find a cloro thats invisible and the player will walk into the cube and not fall off

This is an old post, but for people searching for this the solution is to create an EmptyObject and attach a Collider to it.

. …and, again, as i always say, this is kinda thread that will NEVER get old, as long a people make games in Unity. *Good that admins did NOT have it closed, thanks. So, here, (for now, and all future readers of this thread): you need to make in CODE, and define IN CODE a Square Matrix, after which bound player is considered out of it. Here’s the (my simpler version) you can use, and additionally modify, for the task (you only MUST drag your center of your each map each time to be 0,0,0, in coordinates, for using this script in SUCCESSFUL manner) So, any objects you want to limit how far, or high it can go, just attach this script to it, and enter desired limits in Inspector: (*you may also add your damage call line, later, as well): here, my clean “LimitWorldBoundaries” script:
[68833-limitworldboundaries.zip|68833]

Is there really no way to just turn off gravity? I feel like that may be what some people are looking for. I know that’s what I’m looking for.

Edit: I know you can turn it off in the project, but unfortunately when I do that, I can no longer control the character. They won’t move if there is 0 gravity. It’s very frustrating. Especially when Rigidbody has a “Use Gravity” check box, which doesn’t seem to me to do anything at all on a character.

I’ve answered in a similar thread, but I think this script will be useful to this issue too.

The script prevents the falling. While your terrain will be generated in 0 height (yaxis) at start
everything whats bellow zero height(yaxis) will be automaticaly respawnned to their starting point.
You can use it not just on the player but everything else what uses gravity.

http://answers.unity3d.com/comments/1419816/view.html

This is an old post, but somebody might be looking for an answer. My solution is to check if the player is grounded and if they are crouched. If both are true, four raycasts at the obvious four points around the player point raycasts downwards and if they return true it sets the axis of movement to zero until it detects ground again.