79596929

Date: 2025-04-28 16:45:17
Score: 1
Natty:
Report link

The problem was my trick to + or - 90 degrees to get the forward wall direction, which was backwards on the opposite side of the wall. Thanks to Sanjay Nakate for the solution. Here's the updated code for any wondering:

private void WallStick()
    {
        Vector3 normal = Vector3.zero;

        if (leftWall) normal = leftWallHit.normal;
        else if (rightWall) normal = rightWallHit.normal;

        // Calculate the wall-facing direction only on the XZ plane
        Vector3 wallForward = Vector3.Cross(normal, Vector3.up);  // Vector perpendicular to the wall normal
        if (rightWall) wallForward = -wallForward;

        float targetYRotation = Mathf.Atan2(wallForward.x, wallForward.z) * Mathf.Rad2Deg;

        playerMovement.rotationScript.yRotation = targetYRotation;
    }
Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Shog