# How to do 2D Raycasting on a slope

I have a 2d platformer game where my slope can be set at any angle, so I've setup a middle raycast that points to the ground onto the player to handle the collision. This works perfectly fine on a flat platform, but when I rotate it to a slope the player is offset increasingly more.

Player falls onto the platform with no rotation (works fine).

The player falls onto a platform at an angle with no rotation on the player.

Then when I rotate the player to the angle of the platform.

As you can see the player is offset wrong. Do I have to rotate the rays attached to the player and then push him out of the platform? Or is this overkill and I'm doing something wrong?

This is not overkill, and is in fact the correct technique. It is not too difficult: Imagine this problem from the perspective of the platform... The "up" direction will be the vector <0, 1> rotated by the same amount that your platform is rotated. The code for rotating a vector <x, y> (counterclockwise) by an angle a is:
<x * cos(a) - y * sin(a), x * sin(a) + y * cos(a)>