I'm currently working on a school game project where i need to have the player climb walls and pick up stuff. I am currently stuck in figuring out how to make the player rotate perpendicular to where the model's faces are while he/she moves towards a corner of a wall as shown below.

Something like this:[![Example!](https://i.stack.imgur.com/Y9gmv.png)](https://i.stack.imgur.com/Y9gmv.png) 

I searched for some methods to achieve this but i haven't found anything concrete so far.

Edit: I tried Reasurria's method and it kinda works.

```
if (Physics.Raycast (transform.position, -transform.up, out hit) && hit.collider.GetComponent<WallModifier> ()) {
            transform.rotation = Quaternion.LookRotation (hit.normal, Vector3.right);
            //Physics.gravity = hit.normal * -10.0f;
        }

```

My player does indeed rotate correctly pependicular to the slope/wall but then my camera code completly breaks when trying to actually climb the wall. [This shows how it looks like in first person](https://gyazo.com/50df2ebe3c649ca594e948c4b5e02987) and [this shows how it looks like in the scene view](https://gyazo.com/5e8a5f3294a164c4572cdc158363c213).

While very funny, it is not obviously desired to have such effect.
Here is the camera code:

```
void Update () {
    if (Input.GetKeyDown (KeyCode.Escape) || toggle && Input.GetMouseButtonDown (0)) {
        toggle = !toggle;
    }
    if (!toggle && Application.isFocused) {
        Cursor.visible = false;
        Cursor.lockState = CursorLockMode.Locked;
        var md = new Vector2 (Input.GetAxisRaw ("Mouse X"), Input.GetAxisRaw ("Mouse Y"));
        md = Vector2.Scale (md, new Vector2 (sensitivity * smoothing, sensitivity * smoothing));
        smoothV.x = Mathf.Lerp (smoothV.x, md.x, 1f / smoothing);
        smoothV.y = Mathf.Lerp (smoothV.y, md.y, 1f / smoothing);
        mouseLook += smoothV;
        mouseLook.y = Mathf.Clamp (mouseLook.y, minClamp, maxClamp);
        transform.localRotation = Quaternion.AngleAxis (-mouseLook.y, (Vector3.right + transform.right).normalized);
        character.transform.localRotation = Quaternion.AngleAxis (mouseLook.x, character.transform.up.normalized);
        if (rotateModel && antModel)
            antModel.transform.localRotation = Quaternion.AngleAxis (-mouseLook.y, (Vector3.right + transform.right).normalized) * Quaternion.Euler (0, 90, 0);
    } else {
        Cursor.visible = true;
        Cursor.lockState = CursorLockMode.None;
        Application.runInBackground = false;
    }

}

```

This code was taken by this [person](https://www.youtube.com/watch?v=blO039OzUZc).