Tuesday, June 30, 2015

xna - Slopes in 2D Platformer


I'm dealing with Slopes in a 2D platformer game I'm developing in XNA Game Studio. I was really tired of trying without success, until I found this post: 45° Slopes in a Tile based 2D platformer, and I solved part of the problem with the bummzack answer.


Now I'm dealing with 2 more problems:


1) Inverted slopes:


The post says:


If you're only dealing with 45 degree angles, then it gets even simpler:


y1 = y + (x1 - x)



If the slope is the other way round, it's:


y1 = y + (v - (x1 - x))


My question is, what if I'm dealing with slopes with less than 45 degree angles? Does y1 = y + (v - (x1 - x)) work?


2) Going down the slope:


I can't find a better way to handle the "going down through the slope" situation, considering that my player can accelerate its velocity.


Edit: I was about to post a image but I guess I need to have more reputation he he he... What I'm trying to say with "going down" is like walking towards the opposite direction, assuming that if you are walking to the right, you are incrementing your Y position because you are climbing the slope, but if you are walking to the left, you are decrementing your Y position.




No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...