How is collision detection and movement typically handled in a FPS, particularly handling slight changes in ground height such as stairs (both on incline and decline)?
3 Answers
Entities typically represented by a capsule (cylinder with spheres on the ends) against world geometry (or a simplified collision mesh) for world-ent collision.
Stairs are usually either no-collide with an invisible ramp, or below a certain height you usually get a lift up as a side effect of collision resolution. (you'll get interpenetration with movement as a part of step size, and resolution will pop it out upward as the closest plane)
I think this is how Unreal 3 works, but I could be wrong. I recall seeing a bounding box hierarchy in Source, but I can't remember if that was just for combat. regardless, capsules are simple and fast
In Unity 3D, the easiest way is to have the first person controller. Usually the character has to jump up if the step height is higher than the step offset. But another way to do it is add a box collider and rotate it so that the character can skim the stairs easily, as if it were a ramp.
Brady's answer is good, but if you want a hacky way to do it, you can just cast a ray down to your grounds collision geometry, figure out what triangle it hits, and then use a weighted average of the height of the verts of triangle to figure out the ground height.
-
\$\begingroup\$ What if it's a big, sloped triangle? Can't you somehow find the intersection point of the ray? \$\endgroup\$– wallabraCommented Oct 14, 2018 at 19:02
-
\$\begingroup\$ You already know the position in the plane, you just need the height, which is why I specified weighted average. I recommend you pick up a book on collision detection if you really want to go further. This isn't the best format to learn math. \$\endgroup\$ Commented Oct 16, 2018 at 0:22
-
\$\begingroup\$ Oh, yeah. Weighted average. I think I kind of misread that. My bad. \$\endgroup\$– wallabraCommented Oct 18, 2018 at 2:41