Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Handling tile-based slopes  (Read 3532 times)

0 Members and 1 Guest are viewing this topic.

Cyraxx

  • Newbie
  • *
  • Posts: 8
    • View Profile
Handling tile-based slopes
« on: May 08, 2014, 11:46:47 am »
Hello!

As the title says I'd like to ask you guys if there is a "best" way to handle slopes in a 2d platformer (c++).
We are using an sf::RectangleShape as a collision box wich obviously moves with our character.
Mayble later we would like to implement different angle slopes but for the moment we are using 45° ones.
I have already managed to do half of it, but my problem comes when I try to jump while on a slope or when I try to jump on a slope in wich case I stop on the top of the tile rectangle and not the actual slope.

Thanks in advance for any help :)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11042
    • View Profile
    • development blog
    • Email
Re: Handling tile-based slopes
« Reply #1 on: May 08, 2014, 12:07:51 pm »
There are many, many ways to do it and it's often not trivial. You might find this article interesting.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Handling tile-based slopes
« Reply #2 on: May 08, 2014, 12:13:54 pm »
The separating axis theorem [1, 2] could also be interesting. For my own platformer Zloxx, I used a custom collision detection algorithm for slopes, based on tutorials from a site that has been down for a long time and is only accessible through the Wayback Machine [3].
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

digant404

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: Handling tile-based slopes
« Reply #3 on: August 26, 2023, 07:49:16 am »
I have used the algorithm mentioned in the above post, however, when exiting the left slope - moving up, sometimes (not always) my player is being positioned a tile (in length) higher. I have tried to debug it, but nothing seems to work. Any help would be appreciated. Also, there are any edge cases in this algorithm as mentioned by the jnrdev, do we have a complete working project from where I can reference the algorithm. Thanks in advance