# Detecting collisions with a wall before Update

I'm making a script in unity to control (movement) a character in 3rd person and 3D space.

For that I'm using the CharacterController component.

All pretty standard: inside the update method a Vector3 which will be passed to CharacterController.move is crafted based on the input and collisions, movement and jumping are perfectly fine but I ran into an issue when trying to make a wall jump.

There are 3 steps involved in this:

1. Get the wall to jump of.
2. Check if the player pres the jump button.
3. Move the player in the desired direction.

An this is how I'm doing it:

void OnControllerColliderHit(ControllerColliderHit hit) {
if(mController.collisionFlags==CollisionFlags.Sides) {
//Get wall normal
wallNormal=hit.normal;
isOnAWall=true;
}
}


Now inside Update

if(Input.GetButtonDown("Jump")&isOnAWall) {
//jump...
}


And this work fine in most cases but only if player is giving input or last wall has a similar normal as current so obviously the normal isn't refreshing properly, but why?

Well, after some testing, I discovered that the OnControllerColliderHitis called after the Update method, and this is what I think is happening:

• Physics engine detect the collision and stops the player
• Update method not having any input just send it downwards
• The OnControllerColliderHit method is not triggered(this part I am sure)

Are my conclusions correct?

How can I fix this? (make the player jump without need to move the stick and just with the button)