- Home /
CC Collisions, Locking Y Axis
Hi UA users. I have a problem where I have a character controller on each enemy and they move toward my player to attack (they use the move function if its helpful). The movement works fine but when they collide with each other they ride on top of each other. I tried locking the Y axis, but then they occasionally "merge" with each other. There was already a question on this merging, but its answers just recommended not using CCs. In this game I have no other option. I don't want to disable collisions between the enemies either. There was one GAME for unity that seems to have solved this problem. If you notice, the tanks have the movement and collisions like with CCs. So how can I remove either the riding or the merging?
Here's my script:
var speed : float = 2;
var target : Transform;
var stopRadius : float = 1;
var height : float = 2;
private var moveDirection : Vector3;
function FixedUpdate () {
var controller : CharacterController = GetComponent("CharacterController");
if(controller && target){
var distance : float = Vector3.Distance(target.position,transform.position);
if(distance >= stopRadius) {
moveDirection = target.position - transform.position;
moveDirection = Vector3.Normalize(moveDirection);
moveDirection.y = 0;
moveDirection *= speed;
}
else{
moveDirection = Vector3.zero;
}
controller.Move(moveDirection * Time.deltaTime);
transform.position.y = height;
transform.LookAt(Vector3(target.position.x,transform.position.y,target.position.z));
}
}
Thanks for responding.
Answer by Chris D · Jun 13, 2011 at 11:36 PM
Looking at the character controller docs:
http://unity3d.com/support/documentation/Components/class-CharacterController.html
What are your skin widths and step offsets set to? How large are your enemies? Play around with them a bit and see if that fixes it.
Ok, Found 2 ways to do it. Lock the y axis and increase the skin width, or add gravity and decrease the step offset. Thanks so much, this has been a long problem. :)