I’m trying to combine the character controller and raycasting to do collision for a 2D platformer I’m working on. The character controller collider is handling the collision with the roof / walls, and I’m using raycasting to handle collision with the floor, as people don’t generally have giant hemispheres for feet.
With my current setup I have the character collider slightly off the ground so it doesn’t touch the ground, and relying entirely on my raycasting for the ground collision. (I’ll be using two raycasts, one at the front of the foot, and one at the back)
Here’s the problem - I need to do the raycasts from the new (x) position of the character to find the ground. If I do the raycast before the CharacterController.Move, it doesn’t know exactly where the object will be after the move (if it collides with a wall and doesn’t travel the full distance I intend to move it). It works fine if I’m walking over normal ground and isn’t stopped, but when I’m walking up against a wall, it jitters because it’s doing the raycast from the wrong spot.
If I do the raycast after the CharacterController.Move, then I’d have to either do another Move within the same frame (which the help file says I should only make one call per frame), or manually do it with regular transforms, which bypasses the collision checking altogether, and could potentially stick it through an object, especially if there’s an object close above the character’s head (I’ll only be shifting it on the y axis)
Is one of those solutions fine to use, or is there some better solution to my problem that I’m overlooking entirely?