In-depth Pygame Physics Explanation

preview_player
Показать описание
Tile collision physics confuse a lot of people, so I made this video with fancy MS Paint drawings to explain the concept.

In this tutorial video, I give an in-depth explanation about how I handle tile based physics in Pygame.

Video and code released under: Creative Commons BY-SA 2.0 (CC BY-SA 2.0)
Рекомендации по теме
Комментарии
Автор

You legend!!!
I had this problem for 4 months, and it nearly made my quit coding!
I watched every tutorial, read every website UNTIL I FOUND THIS! I have been a subscriber for a few months now, and I have to thank you for your legendary life saving video!

skysurfer_kon
Автор

Great video! Also the line "the y-axis is flipped" suddenly solved many of my confusions lol.

spacegoat
Автор

I was searching for his for ages. Thanks so much

vaclavkrnak
Автор

Perfect. I was trying to check for both directions at once. Thanks so much for this info super helpful.

izzyanalytics
Автор

TYSM!!
Psst for anyone who is having the player shake when colliding try updating the hitbox of the player before checking for collisions!

OrangeRoot
Автор

Thank you for sharing your knowledge.
Its honestly the only video where i managed to get what is said without having to rewind multiple times.

Ulostdgame
Автор

Super helpful, I didn't want to copy/paste any code from anyone so having to translate this to Javascript was great and you helped me a bunch conceptually pulling off what I was trying to do.

secret-name
Автор

Just so people know, this method will not work if multiple rects overlap and it collides with them near the same area. If you add pygame.Rect(204, 350, 50, 50) to the tile list, it will give you undesired behavior. There probably needs to be some sorting on which ones are closest.

charlesm
Автор

did you find these out by yourself because this would take me millions of years to come up with it. thx for the video helped a lot

edilgin
Автор

Could you make a tutorial for the case of curved slopes like the Fancy Pants game where the player runs up a curved concave ground perfectly and keeps adjusting his angle till he is finally running upside down on the top of the concave curve.

arifkasim
Автор

Could you please reply to this question: can this code be used for moving platforms or would I have to add extra code to handle collisions of that sort.

EDIT: I've fixed it. Also I would like to say that I'm really inspired by the way you create awesome games with pygame :))))

Raja-iqpn
Автор

0:35
As a JavaScript programmer(21 years old, Non professional), I can confirm that Html canvases work the same as does the rest, I honestly think that most programs work this way, But I need to confirm.
Back to the video!

a.j.outlaster
Автор

Nice learning some pygame and listening to ASMR didnt think that day would come xD

pcb
Автор

The ract that I have not realised I could've done movement and collision for the two axis seperately instead of together FOR 4 YEARS is just insane to me

dimi
Автор

Great! I also make tutorials about Python and Pygame and this inspired me thank you so much (:

ratiemand
Автор

question, why did you return the rect from move()? it looks like youre just reassigning rect to player when its already set to rect

tramarthomas
Автор

I am concerned about something I think you may have overlooked, Let's say that the vertical offset is just 3(one tile from the other), But your velocity approaches at 5.
You will then hit both at the same time, My concern is that, Depending on the order in the array itself, You may get stuck in one or the other, Judging by the code, My prediction is that an x motion might result in you clipping to the opposite direction of the tile, A vulnerability that can be used to exit the map.
Does that hold True for Python?...

a.j.outlaster
Автор

thanks a lottt man
but there is one thing u can do
instead of making a function and a for loop to run through, u can use the pygame.collidelistall function.
It returns the index of the rects from the list of rects u provide. It maybe more efficient also because it probably uses recurssion to search through the list
and obviously, there is less code to write and makes things more clean.
anyways, your method is genius. Im gonna use it for the game im making right now

surendarmalai
Автор

I love your voice !!!
And I also love your video !

jeremyho
Автор

Awesome!, Thanks for clearing this collision physics.

anishbangotra