- Home /
 
               Question by 
               QuincyOnIce · Jan 01, 2020 at 11:29 PM · 
                movementraycast3dcharactercontrollercharacter controller  
              
 
              Continuously rotate a gameobject on 1 axis perpendicularly to another gameobject's normal?
I'm now working on a Wallriding system. The actual riding works fine. The turning, not so much.
I've tried Vector3.RotateTowards, but perhaps due to the fact I don't completely understand how I would need to caculate the result I want, it doesn't work. The turning always faces towards transform.forward, when I'd like it to rotate to be perpendicular to the normal of the surface a raycast collides with, but only on one axis.

Maybe this helps clarify what I'd like to happen.
Here's the (likely completely wrong) code I'm currently using to rotate the player:
 transform.eulerAngles = Vector3.RotateTowards(Vector3.ProjectOnPlane(transform.eulerAngles, transform.up), Vector3.ProjectOnPlane(Vector3.Cross(transform.forward, wallNormal), transform.up), wallrunRotationSmooth * Time.deltaTime, wallrunRotationSmooth * Time.deltaTime);
The normal is also found each update call. Any help is appreciated :)
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by QuincyOnIce · Jan 02, 2020 at 12:07 AM
Update: Fixed it using Quaternion.FromToRotation.
 transform.rotation = Quaternion.FromToRotation(-transform.right, wallNormal) * transform.rotation;
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                