6 point collision, what i know

fearspork

New member
i dont know 6502 assembly code and i have no interest in learning, what i do want to do is solve a common problem a lot of us are having with larger players sliding through platforms with out shrinking the hit box, 6502 is a super abstract and old language, googling tile collision will find you stuck in 15 year old dead threads with people who expect you to know 6502 assembly code. so here's what I've figured out

the bounding box is not actually a box , the way its laid out in the platform module is in 4 points labeled 0,1,2,3 that are checked one at a time for collisions with solid tiles. although almost every single game checked collisions differently and with different code , this basic idea is a super common way it was done , the problem with larger sprites and player characters is that the points are stretched to a point where the collisions aren't being detected in the middle, the solution then is to add more points to check

if you imagine your player is on a grid like battle ship each point on the grid has an address like C6 or B4 ( but i dont know how those addresses are written in assembly) in memory they are not stored in a grid they're stored in a straight line to be reassembled as a grid on your screen later, so if you had a 8x8 grid it would be 0,1,2,3,4,5,6,7,... and then the second line down would start at 8,9,10...ect probably in hex values. in the code the number of addresses need to be defined and then a way to retrieve each point and then what to do with the points and then the reactions of these points.

in the platform module there is a .ASM file called TileCollision_Platform_simple_alt.asm wich i am sure is what defines all of this in NESmaker Platform Module. in the file there is already the code for 6 point tile collision but its disabled some how because i'm assuming games run better with less points to individually check.

HandleTileCollision:
;; uses collisionPoint0,1,2,and 3
;; makes use of left+bbox_left, top+bbox_top, width and height of an object to form bounding box.
;; gets collision data for each point.

;LDA ObjectFlags,y
;AND #%10000000 ;; ignore background collisions?
;BEQ dontIgnoreBackgroundCollisions
;LDA Object_flags,x
;AND #%01000000
;BEQ dontIgnoreBackgroundCollisions

;RTS
dontIgnoreBackgroundCollisions:

;;;=== HANDLES TOP LEFT CORNER
LDA xHold_hi
CLC
ADC ObjectBboxLeft,y ;; y is still loaded with object type, so this reads from lut table.
STA tileX
LDA yHold_hi
CLC
ADC ObjectBboxTop,y
STA tileY
JSR GetTileAtPosition
LDA collisionTable,y
;; y is now loaded with tile type
STA collisionPoint0
;;; if it is solid, disregard the other collisions, this should *stop us*.
LDY Object_type,x

;;; === handles top right corner
LDA tileX
CLC
ADC ObjectWidth,y
STA tileX
JSR GetTileAtPosition
;; y is now loaded with tile type
LDA collisionTable,y
STA collisionPoint1

LDY Object_type,x

;;; === handles bottom right corner
LDA tileY
CLC
ADC ObjectHeight,y
STA tileY
JSR GetTileAtPosition
LDA collisionTable,y
;; y is now loaded with tile type
STA collisionPoint2

LDY Object_type,x

;;; === handles bottom left corner
LDA tileX
SEC
SBC ObjectWidth,y
STA tileX
JSR GetTileAtPosition
LDA collisionTable,y
;; y is now loaded with tile type
STA collisionPoint3

;;;;;;;;;;;;;;;;;;six point collision
LDY Object_type,x

;;; === handles bottom left corner
LDA ObjectHeight,y
LSR
STA temp
LDA tileY
SEC
SBC temp
STA tileY
JSR GetTileAtPosition
LDA collisionTable,y
;; y is now loaded with tile type
STA collisionPoint4

LDY Object_type,x

;;; === handles bottom left corner
LDA tileX
clc
adc ObjectWidth,y
STA tileX
JSR GetTileAtPosition
LDA collisionTable,y
;; y is now loaded with tile type
STA collisionPoint5

LDY Object_type,x ;; final restoring corrupted y value




LDA collisionPoint0
ORA collisionPoint1
ORA collisionPoint2
ORA collisionPoint3
ORA collisionPoint4
ORA collisionPoint5
; ;;; all collision points were zero.
BEQ noCollisionHappened

JMP collisionHappened


i'm sure that re-enabling this is super easy for some one who knows how to code, but i dont know what i'm looking at and i cant simply cut and paste someone else's code from some other indie game because every game does this different and the little bit of code i did find i'm sure is not compatible with NESmaker. im sure also it would be easy to add 2 more points to this to make an 8 point collision detection's again i dont know how to do that and the more points you add the slower the game will get.

i've looked at hours of youtube videos and scoured old dev blogs and this was the best resource i could find http://forums.nesdev.com/viewtopic.php?f=2&t=352&start=60 . i hope this gets solved soon or that i at least helped someone who doesn't code what is happening when you slide through a platform
 
Top Bottom