ドキュメントによると、OnControllerColliderHit
Move の実行中にのみ呼び出されます。この移動は、プロパティを直接Move
変更するのではなく、CharacterController の関数によって開始する必要があります。transform.position
public float speed = 6.0F;
public float jumpSpeed = 8.0F;
public float gravity = 20.0F;
private Vector3 moveDirection = Vector3.zero;
CharacterController controller;
void Start()
{
controller = GetComponent<CharacterController>();
}
void Update()
{
if (controller.isGrounded)
{
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton("Jump"))
moveDirection.y = jumpSpeed;
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime); //This is how you move
}
void OnControllerColliderHit(ControllerColliderHit hit)
{
if (controller.collisionFlags == CollisionFlags.Sides)
{
Debug.Log(hit.gameObject.name);
Debug.DrawRay(hit.point, hit.normal, Color.red, 2f);
}
}