Applying constant gravity ends up tresspassing tile. (Video, code and all data provided) #1286
-
Hi, so something a bit strange is happening and I have spent a couple of days without understanding what is happening. Here is the code and I have also attached the required data files to make easy for any one to test it. appDelegate.cpp (removed the resolution scale)
header file
cpp file
|
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 4 replies
-
One thing that I noticed is that when the sprite goes inside the collision tile is because at the line |
Beta Was this translation helpful? Give feedback.
-
Yes. I did this:
What happens is as you see in the video. It holds up for 15 seconds where it is detecting a collision (so both getTileGIDat() return 1 and therefore the if statement that keeps the sprite on top( And some times it seems to happen randomly. There is no problem if the gravity value is around -600. But lower than that it does happen, BUT, not always. For instance, I tried -800 and it runs perfectly. I tried it again, without changing anything, just hitting play again, and it did happen. |
Beta Was this translation helpful? Give feedback.
-
okey, I find a work around it. The issue happens for big gravity when the player is on top of a tile of tile collision.
It still bothers me not know why the issue happens if I just left gravity to -1000, but it is a work around. |
Beta Was this translation helpful? Give feedback.
-
It feels like the problem you have is fps, try to implement the system so that it runs an X amount of times a second at minimum, I'd start at 240 ticks per second and gradually decrease it until you find the gravity bug |
Beta Was this translation helpful? Give feedback.
-
aha! yes, that's it. The gravity (probably combine with relatively small tiles 32*32) is to high for the frame rate. Even if I set it to 600 fps ( which is by doing that |
Beta Was this translation helpful? Give feedback.
-
can you provide a quick snippet in pseudo code? I understand what you are saying but I am no sure how to implement it. |
Beta Was this translation helpful? Give feedback.
you're doing it incorrectly, you should divide the delta time into 4 substeps at minimum, or you can make the system run at a fixed delta time by decoupling it from the update method, first store the current time of the physics system and another time for the game itself and each update while the physics time is lower than the game time you step with a delta time of (1.0 / 60) until the condition in the while loop is no longer met, this way if your game runs at 4 fps the physics will run at 60 no matter what, back to 4 substeps at 60 fps it will yield 240 steps a second, if you find that you need more than 240 tps for your system to be stable then that's inefficient you'd need to fix the …