title: Trying to make the player rotate perpendicular to the model's meshes. Unity
body: <p>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.</p>
  
  <p>Something like this:<a href="https://i.stack.imgur.com/Y9gmv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Y9gmv.png" alt="Example!"></a> </p>
  
  <p>I searched for some methods to achieve this but i haven't found anything concrete so far.</p>
  
  <p>Edit: I tried Reasurria's method and it kinda works.</p>
  
  <pre><code>if (Physics.Raycast (transform.position, -transform.up, out hit) &amp;&amp; hit.collider.GetComponent&lt;WallModifier&gt; ()) {
              transform.rotation = Quaternion.LookRotation (hit.normal, Vector3.right);
              //Physics.gravity = hit.normal * -10.0f;
          }
  </code></pre>
  
  <p>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. <a href="https://gyazo.com/50df2ebe3c649ca594e948c4b5e02987" rel="nofollow noreferrer">This shows how it looks like in first person</a> and <a href="https://gyazo.com/5e8a5f3294a164c4572cdc158363c213" rel="nofollow noreferrer">this shows how it looks like in the scene view</a>.</p>
  
  <p>While very funny, it is not obviously desired to have such effect.
  Here is the camera code:</p>
  
  <pre><code>void Update () {
      if (Input.GetKeyDown (KeyCode.Escape) || toggle &amp;&amp; Input.GetMouseButtonDown (0)) {
          toggle = !toggle;
      }
      if (!toggle &amp;&amp; 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 &amp;&amp; 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;
      }
  
  }
  </code></pre>
  
  <p>This code was taken by this <a href="https://www.youtube.com/watch?v=blO039OzUZc" rel="nofollow noreferrer">person</a>.</p>