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

Author Topic: Gravity and collision problem  (Read 1880 times)

0 Members and 1 Guest are viewing this topic.

Mihrusha

  • Newbie
  • *
  • Posts: 3
    • View Profile
Gravity and collision problem
« on: August 21, 2021, 03:41:43 pm »
my guy have trouble with top collision - he jump throw it, bottom and side collision works, and have trouble with phisics-> guy can run in air after jumping, so i need its running will be only few milisecond and function stop process if i still press button, or  he fall after some time; Also have touble with top collision.
here code example.
https://gist.github.com/Mihrusha/76427bdd09aa27a27c1f4de4f9525238

Mihrusha

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Gravity and collision problem
« Reply #1 on: August 23, 2021, 08:34:59 pm »
So when i render map phisics dont work properly, but when not render map sprites its work ok

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10044
    • View Profile
    • development blog
    • Email
Re: Gravity and collision problem
« Reply #2 on: August 25, 2021, 07:51:04 am »
One way this is usually done is by detecting whether the character is on the ground or not
So if you have "continuous" bottom collision, you allow for full left/right movement.
If the player is in the air, you restrict the left/right movement but make sure to apply gravity.

Here is a very imperfect example I wrote a long time ago. It's very simplified and lots of potential to change, but maybe it can give you an idea.
Official FAQ: https://www.sfml-dev.org/faq.php
Nightly Builds: https://www.nightlybuilds.ch/
——————————————————————
Dev Blog: https://dev.my-gate.net/
Thor: http://www.bromeon.ch/libraries/thor/