I’ve been trying to flatten out the bottom of the character controller I use to move the player in a 2.5D game using two raycasts (one per bottom corner). It works well when walking off the edge of a platform. However, when the player lands on the edge of a platform from a decent jump, the raycast is shanked into the edge (the hit isn’t detected early enough). I’m performing my controller’s .Move (not SimpleMove) in FixedUpdate along with the raycasts, and where the raycast checking occurs (before or after the move, both within FixedUpdate) doesn’t change anything. I’ve also tried using a box collider (rigidbody, continuous, etc.), and it wasn’t any better.
I’ve managed to mitigate the problem using the following code, but it results in an obvious bounce when the character lands on an edge. It at least prevents the raycast from getting stuck so deep that it requires two jumps to get out.
// If we've sunk too deep
if (Mathf.Abs(characterTransform.position.y - hit.point.y) > 0.1) {
// Pop back out
controller.Move(Vector3(0f, hit.point.y - characterTransform.position.y, 0f));
}
Exactly what makes the character controller’s Move() so accurate while the raycasts are so inaccurate? Aside from ditching the controller in favor of a homebrew option, does anyone have a suggestion?
