Game type: side scrolling platformer.
Character: 4-legged dog.
Hello. I was wondering if anyone has experience on rotating a player's sprite if the player is on a slope? Without rotating the bounding box, just the sprite.
The two ideas I've come up with are:
#1) Raycasting: Cast multiple rays a set distance (left/right cast: bottom, middle, top, casting the direction I face) (down cast: bottom left, bottom center, bottom right, casting down) and calculating the angle of the slope I'm on. The thinking here is by having three rays, if I crest a slope, making the top ray not hit anything, then I want to be able to remove that from the angle calculation so I still maintain the slope until I am fully off of the slope.
#2) Slope Object Collision Detection: I could hardcode the player to detect what slope object I am colliding with. Pairing this with a direction facing variable, I could hardcode the rotations. I think this would have issues of shoving my sprite into the ground until my bounding box fully stopped making contact with the slope object.
Am I on the right track? Or does anyone know of an even better way?
This is how I imagine the raycasting idea would work. If the top one no longer collided with a slope object, it would be removed from the angle calculation. The green line represents the calculated slope angle, which would rotate my sprite by the same amount. Note: I kept the dog's sprite further to the side to show the imaginary lines more clearer: