this code is called as the player is wall running, it turns the player as the normal they are attached too changes for use on round surfaces. the issue is /not/ in the “_left” portion, that works entirely as expected. the issue is when the player tries to run around a curved surface on the right side. the player does not rotate, aside from the initial rotation on impact with the surface which uses the same exact rotation code, the difference being that this is in update so it happens for the duration of the wallrun.
if (_wallRunning)
{
if (_left)
{
Debug.Log("left");
RaycastHit hit;
Ray ray = new Ray(transform.position,-transform.right);
if (Physics.Raycast(ray, out hit))
{
transform.rotation = Quaternion.FromToRotation(Vector3.right, hit.normal);
}
}
else if (_right)
{
Debug.Log("right");
RaycastHit hit;
Ray ray = new Ray(transform.position, transform.right);
Debug.DrawRay(transform.position, transform.right, Color.red); //draws ray being cast
Debug.Log(Physics.Raycast(ray, out hit));//returns true
if (Physics.Raycast(ray, out hit))
{
Debug.Log(transform.rotation);//check rotation
transform.rotation = Quaternion.FromToRotation(-Vector3.right, hit.normal);
Debug.Log(transform.rotation);//no change
}
}
}
Here is a link to a (very bad) video showing the problem on youtube.
also:
this has my current hierarchy and the script attached to the player