0
\$\begingroup\$

I'm creating a 3D game, and I need to know how to push a player (axis aligned box/cube) outside a triangle.

How can I get get the push direction?

\$\endgroup\$
  • \$\begingroup\$ How about a sketch showing your problem? \$\endgroup\$ – 3Dave Sep 29 '16 at 12:47
0
\$\begingroup\$

I'm not quite sure what exactly do you need to achieve based on the vague question, but these are some solutions you can consider, assuming you do not use a third party physics engine.

Firstly, if your player is a axis aligned, you can first implement a variation of a ray-box intersection check. One of the fastest method is the slab method. There is a very good article for visualising the slab method on tavianator.com.

Once you are able to detect collisions with your AABB player with rays, it is a simple process to draw 3 rays from one vertex of the triangle to the next to detect if the player is colliding with the triangle. Perhaps with a few more rays if your triangle is bigger than your player.

You can then figure out the push direction based on the player's position, as well as the midpoint of the two points on the ray intersecting the player: enter image description here

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.