I have code that rotates the character to match the normals of walls (matches the walls rotation). This works perfectly until my char turns around 180°. Then instead of rotating Left & Right, it rotates like a windmill.
I believe tht the specific piece of code causing this problem is the transform.rotation within the RotateTowards() function.
if (avgNormal != Vector3.zero) { // Calculate new char rotation to match/be parralel with wall rotation/normals. Quaternion charWallRotation = Quaternion.FromToRotation(Vector3.forward,-(avgNormal / numNormals) * Time.deltaTime); // Rotate char smoothly to match normals of wall if moving left/right. if (Input.GetAxis("Horizontal") != 0) transform.rotation = Quaternion.RotateTowards(transform.rotation, charWallRotation, (wallRotationSpeed * 100) * Time.deltaTime); }
The Debug.Log of the transform.rotation on both the working wall pressing the sideways movement keys.