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

Author Topic: Box2D different angle slopes  (Read 2721 times)

0 Members and 2 Guests are viewing this topic.

Cyraxx

  • Newbie
  • *
  • Posts: 8
    • View Profile
Box2D different angle slopes
« on: July 08, 2014, 11:46:21 pm »
Hi,
  I have created a Box2D based map for my platformer using ChainShape wich has different angle slopes (no more than 45°).
My problem is the slope collision with my player. The player' body has 2 fixtures, a rectangle and a circle bellow it. Whenever I move the player (the method doesn't matter the results are the same) and I stop on the middle of a slope I slowly glide down. I managed to temporarly fix that but the main reason for this post is the fact that whenever I leave a slope l I shoot out because I still have some impulse left from the previous movement. Same thing happens when I enter a downwards slope, or when I stop on a slope and I start moving again.

Entering / leaving the slope:
(The red lines are the desired movement, the black is the movement I have right now)


Start moving on a slope:
(The red lines are the desired movement, the black is the movement I have right now)


Could you please help me out with this problem? I don't mind if your answer is detailed either ;)
Thanks in advance!

Hapax

  • Hero Member
  • *****
  • Posts: 3378
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Box2D different angle slopes
« Reply #1 on: July 09, 2014, 12:44:20 am »
It looks like you need to increase gravity or increase the mass of the object.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Cyraxx

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Box2D different angle slopes
« Reply #2 on: July 09, 2014, 10:20:00 am »
I've tried both already but it doesn't seem to work. :(

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10976
    • View Profile
    • development blog
    • Email
Re: Box2D different angle slopes
« Reply #3 on: July 09, 2014, 11:05:07 am »
If you're lucky someone here knows Box2D well, otherwise this is essentially nothing to do with SFML and as such, you might be better helped on the official Box2D forum or maybe even on StackOverflow.

And some more info on your Box2D setup etc. might be useful as well.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

select_this

  • Full Member
  • ***
  • Posts: 130
  • Current mood: just ate a pinecone
    • View Profile
    • darrenferrie.com
Re: Box2D different angle slopes
« Reply #4 on: July 09, 2014, 11:42:31 am »
I don't know much about Box2d's implementation of gravity, but it looks like the gravitational acceleration is gradual (hence why you're seeing it react late and spending more time in the air than you should).

One simple solution would be to have two states for your player object; a 'ground' state where gravitational acceleration is instant whilst the base of the player object is touching solid ground, and an 'air' state where a more traditional representation of gravity, with its gradual acceleration, comes into effect when the player object jumps or begins falling. If I recall correctly, the early Sonic the Hedgehog games implemented something to this effect.

EDIT: Reformatted for easier reading.
« Last Edit: July 09, 2014, 11:51:02 am by select_this »
Follow me on Twitter, why don'tcha? @select_this

 

anything