- Home /
Box Collider and AI
I am using a simple waypoint script that takes the AI around a small circle of 8 waypoints. The script works fine without any collision detection, but when I add a collider of sorts (Like a box collider) the script stops working. Here's my script below: #pragma strict var grid : Transform[]; var speed : float = 5.0; var current : int; function Start () { } function Update () { if(current < grid.Length){ //variables to determine movement var target : Vector3 = grid[current].position; var moveDirection : Vector3 = target - transform.position; var velocity = rigidbody.velocity; //if close to the waypoint, increase current if(moveDirection.magnitude < 1){ current++; } else { velocity = moveDirection.normalized * speed; } //set the rigid body velocity to move rigidbody.velocity = velocity; } else { current = 0; Could anyone please help me so that I can run my AI script with a physics collider attached to my AI?
I have a rigid body attached to the two AI characters that also have box colliders attached to them. With this script attached, when I run the game, the characters float for a few seconds and then they stop moving all together. I get no errors and when they do not have any colliders on them what so ever they move in a circle, following exactly what the script intends them to do.
Answer by Bunny83 · May 07, 2012 at 05:44 PM
Do you use a rigidbody without a collider? A rigidbody always needs a collider, or where do you attach the BoxCollider? I guess your rigidbody just get stuck on another collider?
What exactly does "stops working" mean? Does it still move but too slow / the wrong way / ...? Do you get errors? What exactly changed when you attached a collider.
The AI characters both have a box collider and rigidbody on them. Without the box collider, the AI does exactly as the script intends and moves in a circle using the waypoints. With a box collider on them, they float for a few seconds and then stop moving all together. There are no errors.
Are you sure that the waypoint can be reached? I mean the pivot point of your character has to be able to reach the waypoint ( < 1 unit) in all direction (x, y, z)
Your answer