Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

When the player falls onto a flat platform Player falls onto the platform with no rotation (works fine).

enter image description here The player falls onto a platform at an angle with no rotation on the player.

enter image description here 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?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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)>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.