title: Rotating a 3D vector 90 degrees relative to another 3D vector
body: <p>I am making a game where the player can climb any surface. </p>
  
  <p>When the player collides with a surface i get the normal of that collision. This is the direction the players "up" vector should align with:</p>
  
  <p><a href="https://i.stack.imgur.com/nyzEX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nyzEX.png" alt="enter image description here"></a></p>
  
  <p>Now, unity provides a handy method to convert two vectors to a rotation:</p>
  
  <pre><code>Quaternion.LookRotation(forward, up);
  </code></pre>
  
  <p>It takes the up vector and a forward vector. As i mentioned i already have the up-vector. My issue is how i get the forward vector.</p>
  
  <p>My current solution is to calculate the forward vector by flipping some axis in the normal:</p>
  
  <pre><code>normal = collision.contacts[0].normal;
  Vector3 forward = Vector3.zero;
  forward = new Vector3(0, -normal.z, normal.y);    
  transform.rotation = Quaternion.LookRotation(forward, normal);
  </code></pre>
  
  <p>This looks okay in most situations:</p>
  
  <p><a href="https://i.stack.imgur.com/zO7bm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zO7bm.png" alt="enter image description here"></a></p>
  
  <p>But when the player collides with a surface where the normal only has a x-value the forward vector is 0,0,0:</p>
  
  <p><a href="https://i.stack.imgur.com/wpFeZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wpFeZ.png" alt="enter image description here"></a></p>
  
  <p>I know i have to take x-component of the normal in to account aswell to avoid this situaion but i am not sure where to plug it in.</p>
  
  <p>Consider this more of a Unity based question that involves the math functions provided by the engine, as oppose to a pure math related one. But any answer is of course appretiated. </p>