How to keep entities grounded and recognize collisions?

Hello,

I’m creating a 2d platformer. I have followed the various ‘Enemy Follow a player tutorial’ I’ve found online. I can get the enemy to chase the player, but how do I get the enemy to stay grounded? I have a collision box that detects interaction with the player, but the collision does not seem to recognize walls or level geometry.

I’ve tried to add a Rigidbody and a checked the ‘use gravity’ box, but nothing seem to recognize collisions. Any advice on how to add gravity through code? Thanks for your help.

Sidenote: I think that the LookAt.FindObjectWithTag"Player" (Pseudocode) was causing the enemy to spin out of control. i’m not sure if this is also causing the enemy to ‘float’

You might already know, but the method you use to move your character determines if collision are detected or not. Moving a character by its transform does nothing for you, only the CharacterController and Rigidbody will help.

You could use nothing but a CharacterController and add gravity manually by calling Move() with a negative y. To follow Unity’s recommendation of calling Move() only once per frame, you may ‘stack’ desired movement into a Vector3 variable which is applied at every frame.

There’s also SimpleMove() that automatically adds gravity…