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.

alt text

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 :slight_smile:

Update:
Fixed it using Quaternion.FromToRotation.

transform.rotation = Quaternion.FromToRotation(-transform.right, wallNormal) * transform.rotation;