Using ProjectOnPlane to slide around adjacent edges

I’m using three raycasts to find the edge directly in front of my characterController capsule and store the normal:

void Update() 
{ 

	forwardRay = transform.position + transform.forward * 0.4f;
	RaycastHit hitInfo = default(RaycastHit);
	var raycast = Physics.Raycast(forwardRay, Vector3.down, out hitInfo, Mathf.Infinity, 1); 

	if (raycast)
	{
		edgeVector = Vector3.zero;
	}
	else
	{
		RaycastHit hitInfo1 = default(RaycastHit);
		var raycast1 = Physics.Raycast(transform.position, Vector3.down, out hitInfo1, Mathf.Infinity, 1);
	
	if (raycast1)
	{
		ground = hitInfo1.point;
		RaycastHit hitInfo1 = default(RaycastHit);
		var raycast2 = Physics.Raycast(new Vector3(forwardRay.x, ground.y + -0.02f, forwardRay.z), new Vector3((-transform.forward).x, Of, (-transform.forward).z), out hitInfol, Mathf.Infinity, 1);

		if (raycast2)
		{
			edgeVector = hitInfo2.normal;
		}
		}
		}
	}
}

I then use ProjectOnPlane to ensure the characterController slides along the edge instead of just stopping dead in it’s tracks:

GetComponent<CharacterController>().Move(Vector3.ProjectOnPlane(Quaternion.Euler(transform.eulerangles) * new Vector3(0f, gravity, currentSpeed), edgeVector) * Time.deltatime);

The trouble is, it doesn’t handle adjacent corners at all and just falls off, since the raycast is only finding the edge normal directly in front of the capsule. Here you can see the red ray is my forward vector in worldspace, and it fires back from there (pink ray) towards the height of the ground beneath my capsule (blue ray): Edgggg GIF by zebbidev | Gfycat

Is it possible to find the next normal in the direction I’m moving, or better yet, wrap the ProjectOnPLane vector around the nearest normal in it’s projected direction? Otherwise, I’m just doing this the wrong way?

@Zebbi, are you rotating the player to face the direction of motion? Because it in your gif doesn’t look like the ray is in front of the direction of motion toward the end of the video. If it’s not rotating then you need 4 ray casts - one for each face.

But either way, I’m not sure what you want to do when you get to a corner: If you want to keep moving around the corner, then I think you need to detect if any two rays are on two different edges/faces at the same time - indicating the player is in a corner, and then you can rotate the player to face the new direction of motion, or what ever you want to do from there.