I have done extensive research on this topic over the past few days, and I cannot find an answer for my exact problem.
So, I have a simple game in which I have a player at 0, 0 with a width of 10x10
player= pygame.Rect(0, 0, 10, 10)
and in addition, the player has a speed of x: 0, y: 10, which will make him fall (y is positive, because the beginning of the screen is in the upper left corner.)
and I have a tile at 0, 100, as shown:
dirt= pygame.Rect(0, 100, 10, 10)
therefore, how can I handle the collision, I already know that I can detect it with Rect.colliderect (Rect).
I tried several ways, but ran into some problems:
I can’t cut the player’s speed to 0 when he stumbled on something, and then move it back until it just touches the object, because it still causes a walking problem, when it walks, I apply +10 speeds in x, but, unfortunately, the game is still handling the fact that it crashes and collides and moves sideways, so it just moves it back to where it started.
I'm a newbie, so a simple answer would be very useful for me, and I would not want to use other third-party modules that would be different if I did not have to.
Update:
Here is an example of the rough test code I tried:
def sim(obj, time, world): time= time / 1000 obj.physProp['vel']= (obj.physProp['vel'][0] + (accel[0] * time), obj.physProp['vel'][1] + (accel[1] * time)) if obj.physProp['vel'][1] > terminalY: obj.physProp['vel']= (obj.physProp['vel'][0], terminalY) obj.pos= (obj.pos[0] + (obj.physProp['vel'][0] * time) + ((accel[0] / 2) * (time ** 2)), obj.pos[1] + (obj.physProp['vel'][1] * time) + ((accel[1] / 2) * (time ** 2))) for ID in world: if obj.getRect().colliderect(world[ID].getRect()) == True: pass return (obj.pos, obj.physProp['vel'])