I need to rotate a character sprite according to the scope of the platform he (a rectangle) is standing or walking on. I have achieved the effect by rotating it according to the slope of the platform he is standing on. But there are two problems:
First, the rotation is not smooth. When the character walks from a flat platform onto a sloped one, it is rotated instantly and also because of that rotation it is pushed up by a little bit.
Second, once he walks off the slope and onto a flat platform again, I cannot rotate the character accordingly. This is because at that point the character would be colliding with both a flat platform and a sloped one (they are placed together), so for a few steps the character will be rotating crazily back and forth because two collision detection functions working together.
I have tried to solve it by detecting the facing of the character and try to figure out which point (left or right) of him touches something first, but it was not working, because I can only detect collision, but not "no collision" or "when character leaves some platform".
I have attached an illustration of the situation. Please help, thanks!
PS: Since I am not allowed to post images, please visit: https://i.stack.imgur.com/jqPjt.png for the image. Thanks.