- Home /
Enemies fall through floor when chasing player.
I have some scenery models with mesh colliders attached, along with enemies placed ontop of them. In my current AI code for the enemies, they chase the player by moving to the players position value, as described below.
function ChasePlayer() { //print ("Chasing Player"); animation.CrossFade("Walk", 1); dir = target.transform.position - transform.position;
dir = dir.normalized;
transform.Translate(dir * speed * 5 * Time.deltaTime, Space.World);
}
However, when the enemy chases the player up a hill, they walk through the floor ignoring the mesh collider, and fall to their death. Each enemy has a character controller and a platformer controller attached.
The game is a 2D sidescrolling platformer if that helps.
Answer by spinaljack · Jun 29, 2010 at 10:58 AM
Couple things you could do:
- Don't edit the bot's transform position directly, it is likely you're pushing them into the terrain, use velocity or give the bot a proper move script like the player has
- Change the bot's collider if it's a mesh collider as they tend to get stuck more easily
- Increase the physics calculations per frame to try and catch collider penetrations (this doesn't solve the source of the problem)
- Add box colliders to the terrain if you're using mesh colliders for the terrain to "reinforce" them
Thanks for the reply.
The reason I don't use rigidbodies is that the enemies behave in ways that do not fit the game. I felt that the problem was with using transform.Translate() to move the player, but I cannot apply a velocity since it does not have a rigidbody. I'll see if I can use Simple$$anonymous$$ove ins$$anonymous$$d and find out if that fixes the problem.
Your answer
Follow this Question
Related Questions
Problem with Flashlight in Horror Game 2 Answers
Problem with a monster (he follows me backwards) 1 Answer
How to handle multiple colliders for one enemy and bullet. 3 Answers
How i make the NPC friend stop following me and start to follow the enemy when he is near???!!! 0 Answers
How can I make my enemy stay on the ground and collide with other objects? 2 Answers