Pygame Jumper collision detection not working

Vincenzo Hamond

I am trying to make a game similar to what is seen in google chrome when the internet is down for my A Level computer science course work. I have run into an issue regarding collision detection and any help would be greatly appreciated.

When i try to declare more than one platform to stop player movement (collision detection) all platforms stop stopping player movement. But when i have only one platform stopping player movement it will work.

All of my code is located here: https://github.com/VincenzoLaRoche/ComputerScienceCourseWork

MegaIng

Your problem is that your are handling the platforms completely separate. So if you stand on one, you are not touching the other one so it makes you fall. For this to stop, you have to modify the t1o player methods collision_detect and do like so:

def collision_detect(self, platform):
    if self.x > platform.x and self.x < platform.x2:
        if self.y + 40 == platform.y:
            return True
        else:
            return False

def do(self):
    self.keys()
    self.move()
    self.draw()
    c1 = self.collision_detect(platform(0, 500, 800, 10))
    c2 = self.collision_detect(platform(0, 480, 400, 10))
    if c1 or c2:
        self.yVel = 0
        Constants.CANJUMP = True
    else:
        self.yVel = 5
        Constants.CANJUMP = False

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Collision detection in pygame not working

From Dev

PyGame border collision detection not working

From Dev

Python collision detection, NOT in pygame

From Dev

Collision detection in pygame

From Dev

Pygame collision detection

From Dev

Color collision detection in Pygame

From Dev

Pygame collision detection

From Dev

PyGame: Collision Detection With Block

From Dev

Initial Collision Detection in Pygame

From Dev

Collision detection in pygame

From Dev

pygame collision detection with walls

From Dev

Why isn't my collision detection working properly in pygame?

From Dev

Collision detection not working?

From Dev

Pygame - Collision detection with two CIRCLES

From Dev

Add collision detection to a plattformer in pygame

From Dev

Pygame checking for collision not working

From Dev

Collision not working for pygame Sprites

From Dev

Pygame Collision not working

From Dev

Pygame circle and its associated rect for collision detection

From Dev

Pygame. Efficient detection of line collision with sprite

From Dev

Collision Detection Javascript Not Working(rather Im not working)

From Dev

2D Collision detection not working

From Dev

Collision Detection hitTestObject not working.. ish

From Dev

Collision detection not working in Unity 2D

From Dev

JavaScript Collision Detection doesn't seem to be working?

From Dev

Collision detection not working for adding 1 to score

From Dev

Why is my collision detection not working properly?

From Dev

Collision detection using kineticJS (getIntersection function not working)

From Dev

Why is my collision detection not working properly?