Need to get the difference between the rotation of a normal and an object
Iv'e been trying to get the difference in rotation between the normal of a wall and the player for some collision calculations (so the player slides along the wall when hitting it at an angle) but i can't seem to get the direction of the normal in degrees. If anyone can help or propose another solution to make the player slide along the wall when hitting it at an angle it would be much appreciated.
Also the reason i wanted to do this in the first place is because the collisions seemed to jitter uncontrollably when running into corners when using the rigid body so i thought i would try and make my own collisions to fix that. If anyone knows a solution to that it would be helpful.
This is what i have done so far but it's far too confusing and doesn't seem proper and i seem to get different angles depending on the wall i collide with meaning it doesn't work.
*Note: "wishDirTransform.eulerAngles" is essentially the players rotation in this case (if you want to be specific its the transform which holds the players intended direction)
float angleOfWall = (Mathf.Acos(hit.normal.x) * Mathf.Rad2Deg);
if ((Mathf.Asin(hit.normal.z) * Mathf.Rad2Deg) <= 91 && (Mathf.Asin(hit.normal.z) * Mathf.Rad2Deg) > 0)
{
if (angleOfWall < 180 && angleOfWall > 90)
angleOfWall = 270 - (Mathf.Asin(hit.normal.z) * Mathf.Rad2Deg);
else
angleOfWall = 360f - (Mathf.Asin(hit.normal.z) * Mathf.Rad2Deg);
}
rotationFromWall = wishDirTransform.eulerAngles.y - angleOfWall;
if (rotationFromWall > 180)
rotationFromWall -= 360;