- Home /
Character Controller can pass through Collider
I made an AI with Character Controller inside. But sometimes, this character controller can pass through Walls (Box Collider) and House (Mesh Collider).
this the script for AI.JS
function FollowPlayer(){
status = AIStatus.Running;
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(ply.position - transform.position), rotateSpeed * Time.deltaTime);
transform.rotation.eulerAngles.x = awakeRot.eulerAngles.x;
transform.rotation.eulerAngles.z = awakeRot.eulerAngles.z;
//transform.position.y = awakePosY;
if(Vector3.Distance(transform.position,ply.position) >= attackRange ){
transform.position += transform.forward * runSpeed * Time.deltaTime;
animation.CrossFade(animations[1].name);
}else AttackPlayer();
}
Oh Yea, sometimes, the character controller can fly (not grounded). Can anybody help me ? Do i need to use Raycast mode ?
Answer by fafase · Oct 29, 2012 at 10:12 AM
For the flying issue you would need to add a constant gravity system.
var gravity : float = 20.0;
private var moveDirection : Vector3 = Vector3.zero;
function Update() {
var controller : CharacterController = GetComponent(CharacterController);
//other movements
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
For the passing through, I would think if your NPC has a CC, use it. Move the guy from it.
At the very last line of this page http://unitygems.com/memorymanagement/ you can download a project that uses a script that would be pretty much do what you need. That is target a position and move the object towards it with CC.
Your answer
Follow this Question
Related Questions
Magical Rigidbody/CharacterController free character...controller - Unity 0 Answers
Help: A collider attached to the character controller of a FPS does not collide 1 Answer
Player falls through floor after 10-20 seconds and above certain resolution consistantly(Bug?) 5 Answers
Character Controller Is Lagging Behind Enemy 2 Answers
Character - Collider With Scene 0 Answers