Prevent enemy from falling off edge


I have a (3d) game where the enemy charges at the player, but the player can quickly avoid the enemy and just let them fall off the platform they’re on. I want the enemies to avoid edges, but I’m not sure how I should start. I’m using rigidbody.AddForce for the enemy movement so I can’t just program them to stop since they keep on rolling.


rigidbody.velocity =; will stop your enemys if you stop adding force!

have you considered adding walls around your platform and just turning of the renderers so the walls are invisible?

From what I understood you want the enemies to stop before hitting the edge of your platform.
Can just do a rayscan each frame like this and check if it collides with the platform, having the vertical rayscan always be done in front of your character (the direction he’s moving)

If the rayscan returns null, then you stop all forces on the object and rigidbody.velocity = like toddisarockstar said.