1
\$\begingroup\$

This one's going to be interesting to explain. Let's say I'm making a geometry based collision system for a platformer, where polygons exist based on the lines that form them. I'm using some basic math formulas, like points from line intersections, and the slope formula, because I want dynamic collisions and dynamic shapes in the game I'm making. It's also important to note that this system is being built with a lot of trigonometry, just in case I want to change the gravity direction in this little platformer of mine.

Now here's the problem: I've got a character with a sensor that goes down and finds the lines they intersect with, and gets the nearest one. This works well enough, and grounds the character to slopes horizontally, just the way I want them to be. The only thing I don't like about using a single sensor, which just so happens to be the biggest problem with it, is the fact that the collision only spans one single pixel; the single sensor. To fix this, I originally thought I could just easily add two more sensors on the left and right of the player, but that comes with more problems. Here's just a couple, along with my attempted solutions:

The player doesn't know which point to snap on to. I originally tried to prioritize the center collision, but if there's a collision on either side, it doesn't affect the player. I set it to which collision was the closest to the player, but that meant that going down slopes would make the player stick to the slope awkwardly on the left or right collision.

I tried another system, which was left and right first, then check center if both succeeded. This did not work as intended at all.

I had a third system I tried, which was low, high, center collisions. If would check the further collision first, then the closer one, and then would check the one in the center.

Needless to say, none of these solutions ever worked. All I want is a system where the player snaps to the middle slope, but collision can still adequately interact with them no matter what direction or sensor it's colliding with, as well as the player being able to walk slightly outwards of solids than just their center point.

I apologize if this is confusing, I'm not sure how to explain it outside of a 3 sensor collision system based on lines. I've tried more hacky solutions, but I'd generally want to avoid those because the geometry being used is meant to be more dynamic.

I just want to know if there is a system of polling the sensors that allows me to keep the behaviors I want, even if it's a little more complicated than what I have currently.

\$\endgroup\$

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.