Two questions about slopes

Nomosoft

  • Posts: 122
I am working on a platformer that involves sloped terrain. Instead of rolling my own, I'm using the slope detection behavior from the Run-n-Jump kit. I have a couple of questions I'm hoping someone can help me with.

1) What is the "slope grade" reported by the slope detection code? A 45 degree incline should be a 100% grade, but when my actor hits a 45 degree slope, the "slope grade" is reported as 29.xxxx.
2) I want my actor to elegantly rotate to match the slope he is on. I'm wondering which of several options my fellow Stenylers think is best.
2a) One option is to use multiple collision boxes at the bottom of my actor (which is a vehicle, not a humanoid character), and when the first box hits, rotate a certain percentage of the slope, when the second box hits, rotate a little more, and so on.
2b) The other option I am considering is turning on rotation in physics (currently, the actor cannot rotate in the physics engine), but limiting it to +/- X degrees of rotation. Then, of course, I need to make sure he only rotates when entering or leaving a slope, and not when bumping into things in mid-air, or when ramming a wall. Another problem with this approach is that my actor seems to want to rotate FORWARD when the bottom of his collision box hits a slope, like he's tipping forward from momentum. I don't know how well I can counter this by changing the shape of his collision box.

I'm open to suggestions. I usually do my own crude physics with platformers, but I would really like to use the built-in Box2D functionality, this time around.

Hi Nomosoft

This might not help but it's made a big difference to my upcoming game. I created a slim actor, with a custom polygon shape that looks like a 45 degree stick. I then drag this onto each sloping tile. This allows me to do a hit test and find out if the actor is touching a slope. You could do a sloping actor for each type of gradient in your game.

See the attached shot.

In the finished game, these will be made invisible.

Abigayl

  • Posts: 807
For the rotation, if you have the x values of the slopes stored, you can compare the x of the actor to the x of the slopes to see how far on it is and rotate the actor from there (similar to your multiple collision idea but might be simpler to implement).
If you need help, please check my tutorials either here or Kongregate (http://www.kongregate.com/accounts/Abigayl) or come over to my stream: http://www.livestream.com/poweredbyflowers