- Home /
why is collider not colliding?
i am making an enemy AI but for some reason the enemy pass through any wall even if they have colliders on them but he does not pass through the floor. I am guessing that i dont use the proper way to do this so i want to know what i have done wrong and how should i do this.
here is the part of the code that control the movement :
function Update () { var playerDist = Vector3.Distance(player.position, transform.position);
if (playerDist <= chaseDist )
{
state = "chase";
} else
{
state = "patrol";
}
if(state == "patrol")
{
Debug.Log("patrol");
transform.Rotate(0, wanderRotation, 0);
vectorSpeed = 1;
transform.Translate(Vector3.forward * Time.deltaTime);
crt += Time.deltaTime;
if (crt >= 3)
{
wanderRotation =0;
}
if (crt >= 15)
{
wanderRotation = Random.Range(2,-2);
crt = 0;
}
}
if (state == "chase")
{
Debug.Log("chasing");
Local(player);
vectorSpeed = 2;
}
}
function FixedUpdate(){
moveDirection = Vector3(0, 0, vectorSpeed); moveDirection = transform.TransformDirection(moveDirection); moveDirection = speed; moveDirection.y -= gravity Time.deltaTime;
var controller : CharacterController = GetComponent(CharacterController);
var flags = controller.Move(moveDirection Time.deltaTime); grounded = (flags & CollisionFlags.CollidedBelow) != 0; if (controller.collisionFlags & CollisionFlags.Sides) { vectorSpeed = 0; if (grounded) { moveDirection.y += jumpSpeed Time.deltaTime; } } }
Answer by Hybris · Sep 29, 2012 at 08:34 AM
transform.Translate ignores colliders, I know it' s weird, but why dont you move with `CharacterController.SimpleMove?`
Your answer
Follow this Question
Related Questions
AI controller script, Enemy movement issues 0 Answers
Keeping Character From Walking Through Walls 1 Answer
Small Project, tutorials/help needed 0 Answers
Problems In Flocking Algorithm 1 Answer
Enemy AI With changing Player 0 Answers