- Home /
Collisions between two CharacterController objects?
(I am using the 2D Lerpz tutorial)
I have one prefab that implements a custom version of the PlatformController script, which utilizes CharacterController for collisions. My custom version implements functions for enemy AI, essentially, and I want enemies to be able to collide with each other and perform certain actions on the collision.
I am using a simple script to detect collisions and print them out on the screen:
function OnControllerColliderHit(hit : ControllerColliderHit) { var gameObj : GameObject; gameObj = hit.gameObject;
Debug.Log(gameObj.name);
}
It's important to note that this PlatformController script implements its own form of gravity as well as some light filtering for physics, it's for a simple 2D platformer.
When the enemies are running around the level, this works fine - it displays the debug message for all the platforms and objects they run into, crates, barrels, posts, etc. However when they hit another enemy, they physically collide and can't move any further, but no collision debug message is actually output.
http://answers.unity3d.com/questions/7091/charactercontrollers-dont-register-collisions-with-each-other This question indicates that CharacterControllers can't actually easily collide with each other, which gives me two questions: 1) Is there any kind of easy way, or could I add a second collider to the object? 2) How would I specifically go about switching from the PlatformController+CharacterController implementation for these enemies into something using rigidbodies and normal colliders? For this tutorial script, would it be very difficult?
Answer by Bravini · Oct 20, 2010 at 06:55 PM
2- You could add more colliders on objects parented to your character object and they will collide with each other.
1-Not sure about this one, but try setting your character colliders to Convex and it should work fine.