Jump to content
  • Advertisement
Sign in to follow this  

Better slope collision on platformer game

This topic is 2117 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Okay so I have collision with slopes working fairly well on my platformer but I'm thinking it could be better.


Basically, I'm using the Tiled Map Editor, and I draw polylines on the floors where you're supposed to collide. In the game, I basically create a ray between the player's current position, and the position he's going to be in next, and check if it intersects one of these lines. If it does, the "onGround" bool is set to true (which disables gravity), and then I get the gradient of the line segment, find out how far along the X axis I am of it, multiply that by the gradient and set that as the Y coordinate. Simple maths, but it works and it's solid.


However, when I'm running downhill, I'm moving along the X axis, leaving the ground for a bit, falling until I hit the ground, etc. So very little time is actually spent on the ground, which means you can't jump ('onGround' has to be true to jump).


So, I was thinking of following these paths directly, but it's a little bit complicated and I'm confused about how to do it. Note, there are many polylines per level, and most have more than one line segment to them. Does anyone have any experience with this? I could use some help.



Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!