x


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.

more ▼

asked Jun 29 '10 at 10:43 AM

Deikkan gravatar image

Deikkan
198 8 9 19

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Couple things you could do:

  1. 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
  2. Change the bot's collider if it's a mesh collider as they tend to get stuck more easily
  3. Increase the physics calculations per frame to try and catch collider penetrations (this doesn't solve the source of the problem)
  4. Add box colliders to the terrain if you're using mesh colliders for the terrain to "reinforce" them
more ▼

answered Jun 29 '10 at 10:58 AM

spinaljack gravatar image

spinaljack
9.1k 18 31 92

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 SimpleMove instead and find out if that fixes the problem.

Jun 29 '10 at 11:20 AM Deikkan
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1765
x672
x321

asked: Jun 29 '10 at 10:43 AM

Seen: 1649 times

Last Updated: Jun 29 '10 at 03:09 PM