Question by 
               CodyCantEatThis · Nov 13, 2019 at 06:46 PM · 
                rotationraycastquaternion  
              
 
              Rotate player to align with floor
I can't seem to figure out how to get my character to walk along the normal of a surface. This is what I have tried and I can't figure out why it doesn't work:
         Ray ray = new Ray(transform.position, Vector3.down);
         RaycastHit hit;
 
         if (Physics.Raycast(ray, out hit))
         {
             transform.rotation = Quaternion.LookRotation(hit.normal);
         }
Instead of being perpendicular to the surface, my character will walk parallel to the ground.
Also, I have a part of my code that helps move my character based on the camera's look direction, so I want to make sure whatever solution I find is compatible with this:
 if (Input.GetAxisRaw("Horizontal") != 0 || Input.GetAxisRaw("Vertical") != 0)
             {
                 transform.rotation = Quaternion.Euler(0f, pivot.rotation.eulerAngles.y, 0f);
                 Quaternion newRotation = Quaternion.LookRotation(new Vector3(moveDirection.x, 0f, moveDirection.z));
                 playerModel.transform.rotation = Quaternion.Slerp(playerModel.transform.rotation, newRotation, rotateSpeed * Time.deltaTime);
             }
               Comment
              
 
               
              Your answer
 
 
             Follow this Question
Related Questions
transform.rotation spazes out 0 Answers
Making a portal inspired game - Need help! 0 Answers
Rotating 3d person character 0 Answers
Making 2D Compass From Quaternion 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                