2
\$\begingroup\$

I am working on my collision system right now and I wondered how you can actually walk on a mesh. For example I'm thinking about a dynamically created little village and I want to be able to move the player across roofs etc.

I read about two different approaches to that problem.

  1. Simulate the next step and test if the step can be performed. If it's all right, perform that step or abort otherwise
  2. Perform the step and let the collision system handle a collision in the next frame.

Now, with regards to speed and accuracy, which one is better suited for my problem. As a sidenote: the player should also be able to climb stairs and I also want to prevent the player from moving on very steep parts of the model.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Usually to see if the character is on the ground you raycast downwards from the characters origin and get the distance. That distance should be the model height if it's on the ground. Then if you don't want a character to fall off a ledge all you need to do is take the velocity vector you're about to apply and calculate the new position of the character (by adding vel*dt to the origin) and then just use that point to raycast downwards to get the new distance. If the distance is bigger or smaller then some threshold then set the velocity to 0.

\$\endgroup\$
6
  • 4
    \$\begingroup\$ As an addendum, it's not uncommon to have separate visual meshes and walkable meshes, with the latter having much simpler geometry with carefully chosen boundaries. You can keep a player snapped over the walkable mesh even when jumping. The walkable mesh can include additional properties like whether the node is climbable, a slide, muddy/water that slows the player, etc. This is often called a nav-mesh, especially when discussing path-finding. \$\endgroup\$ Sep 19, 2013 at 1:47
  • \$\begingroup\$ what you say relies on two facts. 1) The model has the same height wherever the player can stand. 2) The model is positioned on the ground. I don't want to assure 1) and I can't assure 2). I thought about raycasting downwards too, but if the player stands on the edge of a structure, the raycast may fail as it does not hit the model the player is standing on. @SeanMiddleditch: good addition, but I won't be able to use a grid-based path-finding system anyway so there is no need for a nav-mesh. \$\endgroup\$
    – rootmenu
    Sep 19, 2013 at 14:31
  • \$\begingroup\$ I have no idea why you are conflating grids and nav-meshes. You can have overlapping areas with walkable meshes, too, as well as jumping, flying, etc., you just need to be a little more clever with your connectivity data and remember which overlapped chunk the player is over. You can store height information for each tri of the mesh to help handle flying, variable-height models, etc. For support for overlapping walkable meshes, see github.com/memononen/recastnavigation and it algorithms and data-structures as a jumping point. \$\endgroup\$ Sep 19, 2013 at 15:56
  • \$\begingroup\$ Generally speaking the origin of the model does have a fixed height from the ground plane. Even if the character is ducking or animating something like a jump or a land. \$\endgroup\$
    – nykwil
    Sep 19, 2013 at 19:14
  • \$\begingroup\$ You're not limited to one ray cast to determine if they're grounded, I usually take one in front and one to each side. To calculate the the slope and also make sure each foot is on the ground. \$\endgroup\$
    – nykwil
    Sep 19, 2013 at 19:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .