SFML community forums

Help => General => Topic started by: Mihrusha on August 21, 2021, 03:41:43 pm

Title: Gravity and collision problem
Post by: Mihrusha 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
Title: Re: Gravity and collision problem
Post by: Mihrusha 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
Title: Re: Gravity and collision problem
Post by: eXpl0it3r 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 (https://github.com/eXpl0it3r/Examples/blob/master/SFML/SimpleAABB.cpp) 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.