I need some help on my collisions
Root / Programming Questions / [.]
PerskaCreated:
I have this game I am working on, and it has some basic collisions right now.
But there are some problems: if the player hits a wall with high speed, they can do stuff that is not intended. If I changed the order of the collisions, then the player's X coordinate would change every time the player hits the ground with high speed.
So what I would need is some help making the collisions less bad!
The public key for the program is QDK3AX9D.
The collisions start at line 83.
If this information was not enough then tell me what info did you need.
can you post the collision code? I can't use my 3DS right now.Here you go:
the code and variable explanations
IF CHKCOL(PX#-6,PY#+8)==1 THEN G%=1:PY#=FLOOR(PY#/16)*16+8 IF CHKCOL(PX#+6,PY#+8)==1 THEN G%=1:PY#=FLOOR(PY#/16)*16+8 IF CHKCOL(PX#-6,PY#-7)==1 THEN JMP%=0:YVEL#=1:PY#=FLOOR(PY#/16)*16+8 IF CHKCOL(PX#+6,PY#-7)==1 THEN JMP%=0:YVEL#=1:PY#=FLOOR(PY#/16)*16+8 IF CHKCOL(PX#-7,PY#-7)==1 THEN PX#=FLOOR(PX#/16)*16+7:VEL#=0 IF CHKCOL(PX#-7,PY#+7)==1 THEN PX#=FLOOR(PX#/16)*16+7:VEL#=0 IF CHKCOL(PX#+7,PY#-7)==1 THEN PX#=FLOOR(PX#/16)*16+8:VEL#=0 IF CHKCOL(PX#+7,PY#+7)==1 THEN PX#=FLOOR(PX#/16)*16+8:VEL#=0CHKCOL is just a function that gets the tile in the map array based on the coordinates given. G% is the variable that stores if the player is on ground. VEL# and YVEL# are the velocity variables PX# and PY# are the player coordinates
Hmm...
Try something like
IF CHKCOL(PX+VEL,PY)==1 THEN INC PX,VEL IF CHKCOL(PX,PY+YVEL)==1 THEN INC PY,YVELThis prevents the player from being moved into a wall in the first place, hopefully. However, it will allow you to travel through walls if you go fast enough, and you will get stopped before hitting a wall when you go fast. To fix this, do multiple checks, like this:
FOR I=1 TO CHECKS IF CHKCOL(PX+VEL/CHECKS,PY)==1 THEN INC PX,VEL/CHECKS IF CHKCOL(PX,PY+YVEL/CHECKS)==1 THEN INC PY,YVEL/CHECKS NEXTThis will prevent the player from "colliding" with a wall too early, or going through the wall, when moving fast. I think most video games preform multiple collision checks; I know Super Mario 64 does 4 of them. I tested them, and they work. The first one does let you walk slightly into the corners of blocks (well, now we know that Link's Awakening uses a similar collision detection!)