nesdev.comhttp://forums.nesdev.com/ Collision Logichttp://forums.nesdev.com/viewtopic.php?f=2&t=15883 Page 1 of 1

 Author: dougeff [ Sun Apr 30, 2017 6:45 pm ] Post subject: Collision Logic I've been thinking about improving my code for 'what to do if collision'.I've been doing something like...collision left, add 8, and \$f0collision right, and \$f0(plus or minus an adjustment).ie, aligning to the metatile.SMB1, just does a-collision and facing right (-1 x)collision and facing left (+1 x)and if you manage to face the wrong direction, you pass through the wall (well known glitch).So I looked at a few more games. This seems to be a better approach...Ducktales...collision rightLDA \$0720,X @ \$0720 = #\$77 ;x positionCLCADC \$D433,Y @ \$D434 = #\$0A ;right side offsetSTA \$0006 = #\$81...LDA \$0006 = #\$81AND #\$0FSTA \$0006 = #\$01LDA \$0720,X @ \$0720 = #\$77SECSBC \$0006 = #\$01STA \$0720,X @ \$0720 = #\$76 ;new x positioncollision leftLDA \$0720,X @ \$0720 = #\$28 ;x positionCLCADC \$D433,Y @ \$D436 = #\$F6 ;left side offsetSTA \$0006 = #\$1E...LDA \$0006 = #\$1EAND #\$0FEOR #\$0FSECADC \$0720,X @ \$0720 = #\$28STA \$0720,X @ \$0720 = #\$2A ;new x positionThis seems a bit complicated to me.What do think is a good method? Is there any other approaches to this?

 Author: Oziphantom [ Mon May 01, 2017 12:01 am ] Post subject: Re: Collision Logic I guess they do the *(-1) to save a byte per collision rect in the ROM? the store centre pos of their objects and then +/- a fixed offset? If you move the world but keep the player in a fixed position on the screen, they your checks just become fixed index look ups Or if you have a small dead zone you can keep counters to shift the locations you need to check.If you move around the screen, I usually convert the player pos to "tile" space, which is then aligned to POW2 and masks make it easy to pull out of the "walls", then you offset by X,Y Scroll and store back. However sometimes I need to do multiple points to test, so while I might just do AABB checks, I sometimes also add feet and body and head based checks. Depends on what the game needs. But then I normally don't have "meta sprites" and all my positions are stored based on TL. Also max movement speed per frame is important. If you only move 1 or 2 px per frame, then you can do simple stuff, if you move 4-8 and you have single char walls, you have to be more advanced.

 Author: Sumez [ Mon May 01, 2017 12:32 am ] Post subject: Re: Collision Logic My "world" collision detection routine (which does need to be tightened up a lot!) is written in a way that gives me easy access to the remainder of the coordinate that pushes the object into a wall/floor. Since we're usually working with 8x8 or 16x16 collision tiles in NES games it's basically just AND'ing the low byte of the coordinate.Depending on how your movement logic works, it's really just a matter of subtracting that value from your coordinate or velocity (if it hasn't been applied yet)Collision detection in Super Mario Bros is terrible, to be honest. But it does have a fairly advanced movement scheme, so I won't hold it against it.

 Page 1 of 1 All times are UTC - 7 hours Powered by phpBB® Forum Software © phpBB Grouphttp://www.phpbb.com/