When an object under the control of this script runs flat into a wall, say a box with no rotation (clearly a side collision), the hit does not register. You can rotate the obstacle and sometimes the collision will register, maybe when moving backwards, but not in the simple case of a direct head-on collision. Putting rigidbodies on one or both objects does not help. What gives? I need to be able to detect these.
var cc : CharacterController;
var moveDir = Vector3.zero;
var speed = 10.0;
var grav = 20.0;
@script RequireComponent(CharacterController)
@script RequireComponent(AudioSource)
function Awake()
{
cc = GetComponentInChildren(CharacterController);
}
function Update()
{
if (cc.isGrounded)
{
moveDir = transform.forward * Input.GetAxis("Vertical") * speed;
}
if( cc.collisionFlags == cc.collisionFlags CollisionFlags.Sides ){
audio.Play();
}
moveDir.y -= grav * Time.deltaTime;
cc.Move(moveDir * Time.deltaTime);
}