LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

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. EDIT: what do you mean by "stuff that is not intended"

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#=0
CHKCOL 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
By stuff that is not intended are stuff such as wall jumps, velocity for the height getting reset to 0. All because the player is not pushed away in time.

Hmm... Try something like
IF CHKCOL(PX+VEL,PY)==1 THEN INC PX,VEL
IF CHKCOL(PX,PY+YVEL)==1 THEN INC PY,YVEL
This 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
NEXT
This 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!)

So where I would put the possible solutions in the code?

So where I would put the possible solutions in the code?
replace
INC PX#,VEL#
etc.
EDIT: I tested the program and it seems to work perfectly... Did you update the code or something? EDIT2: with some more testing, I noticed some strange behavior occuring at the corner...

Okay, I have them working for now. Thanks for the help!