Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8741971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:24:54+00:00 2026-06-13T11:24:54+00:00

I’ve been doing extensive research on this topic for the past few days and

  • 0

I’ve been doing extensive research on this topic for the past few days and I can’t seem to find an answer for my exact problem.

So, I have a simple game set up where I have the player at 0, 0 with a width of 10×10

    player= pygame.Rect(0, 0, 10, 10)

and aside from that, the player has a velocity of x: 0, y: 10, which will make him fall (y is positive because the origin of the screen is at the top left.)

and I have a tile at 0, 100, as shown:

    dirt= pygame.Rect(0, 100, 10, 10)

so, how can I handle collision, I already know I can detect it with Rect.colliderect(Rect).

I’ve tried a few ways, but encountered some problems:

I can’t cut the player’s velocity to 0 when he hits something and then move him
back until he’s just touching the object because that still causes the problem of walking, when he walks, I apply +10 velocity on x, but unfortunately, the game still processes that he is falling and colliding and moving sideways, so it just moves him back to where he started.

I’m a beginner, so a simple answer would be appreciated, and I would like to not have to use any third party modules other that pygame if I didn’t have to.

Update:

Here is some of the rough test code I have 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'])
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:24:55+00:00Added an answer on June 13, 2026 at 11:24 am

    The Pygame API invites you to write all your game subjects in an Object oriented way – so that your falling character will have all the “methods” and “attributes” to properly respond to things on the scenario – like hitting something.

    So, if your character is defined for something as simple as:

    class Char(object):
        # these start as class attributes, 
        # but whenever they are assigned to with a "self.var = bla" in
        # a method, an instance attribute starts existing
        x, y = 0,0
        vx, vy = 0,0
    
        def update(self):
            self.x += self.vx
            self.y += self.vy
    

    And your external code, upon detecting a collision, could do just this:

    def mainloop():
       while True:
           ...
           obj.update()
           if obj.getRect().colliderect(world[ID].getRect()): # don't do "== True" in `if's - it is just silly
                 # take character back to the precious position
                 obj.x -= obj.vx
                 obj.y -= obj.vy
                 # zero out velocities to make it stop:
                 obj.vx = obj.vy = 0
    

    And so on – you will soon perceive thinking of your game “things” as “objects” as they are used in programing make the code flows quite naturally – as soon as you get the way this works, look at Pygame’s sprite module – which allows you to automate a lot of checks, and updates without having to explicitly write for loops for each check

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am doing a simple coin flipping experiment for class that involves flipping a
I have this code to decode numeric html entities to the UTF8 equivalent character.
This could be a duplicate question, but I have no idea what search terms

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.