Multiplayer Collisions (Local)

Ahoy there, pleased to make y’all collective acquaintance. Please forgive my noobness, we’ve not been MakeCoders for very long, but the youngster would like to bring his game idea alive and I’m trying to help him figure out the bits he hasn’t quite figured out yet. This has gone pretty smoothly so far, watching tutorials and such, but we’re having an issue with multiplayer player on player collisions.

The gist of the game is a single screen 2 player battle where the players run and jump around trying to jump on each others head. If a player has been jumped on, said player will lose a life and respawn, this continues until a player has 0 lives left.

We’d like to detect collision between the bottom of a player sprite and the top of another player sprite, but we’ve only come across this kind of collision detection with player sprites on walls, where you can for example detect if the bottom of a player sprite comes in contact with a wall (see below). Is is possible to do this kind of collision with player on player sprites?

Screenshot 2021-10-31 10.34.13 AM

We tried to do a workaround where we’d check to see if a player sprite overlaps another player sprite and then check if the player was falling, which although not perfect, would tell us that the player was falling onto the other sprite, and might suggest that they jumped on them. However, we’ve hit a bump as it seems to only work for player 1, at first I thought it was because the code to detect the collision started with player 1, but we swapped it so that player 2 was checked first and it still only worked for player 1. The code is below:

Obviously, detecting the bottom of a player overlapping the top of another player would be ideal, but if that’s not possible, some guidance as to what we’ve done wrong with the workaround would be greatly appreciated. Thanks kindly for your assistance. May the universe throw good times in your general direction and all that jazz!

Oh my goodness, I just figured it out. I was just over-complicating it. There was no need to nest the if statements inside if statements, a simple “if player-one vy velocity y > 0” and “if player-two vy velocity y > 0” do the job perfectly fine. Apologies.

Why don’t you try a simple ‘If Player 1’s Y is higher than Player 2’s Y’, then lose a life and vice versa for the other player? You can check the How to Make a 2D Platformer Game Part 2 tutorial for more detail on this (Enemy AI).

Thanks, that seems to be working. I’ll check out that tutorial too. Have yourself a most splendiferous day!

1 Like