A more elaborate algorithm such as SAT (separating axis theorem) would give a more precise normal between polygons
Yeah I read about SAT here and there but implementing it is a different story. The reason why I did it with a raycast was that it's a simple solution that I'm familiar with, even if not perfect. But I might have to go for "perfection" here because of the jank.
After the ray cast and comparing the normal you push out of the solids with a loop. First you say you try to push out left then right. The push out right is not doing what you think it’s doing. You’re just moving at the opposite angle which is back into the solids.
Uhm I do believe I have the logic correct here though. I first attempt to push out to the left, if that succeeds I keep the position and don't push out to the right anymore. And if pushing out to the left fails, I reset the position, then attempt to push out to the right. If that succeeds I keep the new position, otherwise I reset again (no pushout). Maybe not the cleanest code though but it's WIP :) I suppose a better version would be to do both attempts and see which direction needs the least pushout to work, then pick that one.
I also see you’re using the reflection angle when doing the pushing. You possibly could try using the normal instead.
I did try the normal angle which zooms the player along the slopes. I think I ended up using the reflection angle because it conveniently simulates a kind of friction and slows the player down more if the slop is less steep. Otherwise the player would zoom along the slope at crazy speeds.
Nvm I was silly and my brain kind of didn't compute that the reflection angle is not what I was actually looking for. I was indeed looking for the normal angle.
My basis for this was this tutorial for corner correction and I just kinda tacked on from there.
youtube.com/watch