collider that OnControllerColliderHit detects but doesnt effect the characters position?

hey there,

i am currently trying to let my character swim if it is under water. To detect that i thought about theOnControllerColliderHit() function since im using a gamecontroller instead of a rigidbody.

my code looks like this:

void OnControllerColliderHit(ControllerColliderHit hit) {
   if (hit.gameObject.tag == "Water") {
        isSwimming = true;
   }
}

when i apply a collider to the water surface it will detect the collision with the water but the character will of course walk on the water instead of going under it since it is a collider. So what do i have to do?

Thank you!

Use a trigger for the water and use code like this on the water:

void OnTriggerEnter(Collider other) {
    if (other.gameObject.tag == "Player") {
         other.GetComponent<playerScript>().isSwimming = true;
    }
 }
 void OnTriggerExit(Collider other) {
    if (other.gameObject.tag == "Player") {
         other.GetComponent<playerScript>().isSwimming = false;
    }
 }

You only need to fill in the name of the actual script that has the isSwimming field.

Good luck!

-Gameplay4all