+ 1

Help!!! What's wrong in this code?

Hi, everyone I don't know ... 😥😥😥 ... why does the player fall through the floor, I actually wanted him only fit through small holes (when he is exactly on the hole). But he always falls through the floor when he is right on any block Can anybody help me ... i would be very happy. Hoping i will get some answers, S.A. https://code.sololearn.com/Wa2A10a20a24/?ref=app

8th Apr 2021, 10:56 AM
Sebastian Ahlborn
Sebastian Ahlborn - avatar
8 ответов
+ 1
If you want to check for an collision on all side of the player you need both x and y coordinates. X is for the left and right side of the player and y is used to check the top and bottom of the player. I've change playerXPos to playerYPos at line 103 and 108, I also logged the variable tor to help with this point. I suggest you console.log tor on your original code to see the difference Take a look and see if this the result you were expecting. https://code.sololearn.com/W86a2403a3a1 btw - You have to tap on the game board to bring it in focus so you can you use the keyboard to move the player around.
8th Apr 2021, 2:55 PM
ODLNT
ODLNT - avatar
+ 1
ODLNT THANK YOU!!!!!!!!!! IT WORKS NOW! THANK YOU VERY MUCH!!!!!!!!
8th Apr 2021, 4:26 PM
Sebastian Ahlborn
Sebastian Ahlborn - avatar
0
You get out of the matrix Working with try/catch could do it.
8th Apr 2021, 11:23 AM
Oma Falk
Oma Falk - avatar
0
Frogged no, no exception is throwed. The problem is that the player can fall throu the floor. I'm goint to fix the other error later.
8th Apr 2021, 11:27 AM
Sebastian Ahlborn
Sebastian Ahlborn - avatar
0
Try/catch is the idea how to fix😉
8th Apr 2021, 11:37 AM
Oma Falk
Oma Falk - avatar
0
At line 108 are you checking for playerXPos or playerYPos?
8th Apr 2021, 12:49 PM
ODLNT
ODLNT - avatar
0
ODLNT playerXPos, because I need to check: if the player is exactly at an block (an not on onother), I should only check the block below the player.
8th Apr 2021, 1:00 PM
Sebastian Ahlborn
Sebastian Ahlborn - avatar
0
You are very welcome. Keep up the good.
9th Apr 2021, 9:51 AM
ODLNT
ODLNT - avatar