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

Glitchy Collision Detection. HELP!!!

Root / Programming Questions / [.]

the_squat1115Created:
Well, I'm working on a new platformer game called Kuni's Adventure, but... I had finally made a sample of collision detection, and... Yep, it's very, very glitchy. Some screenshots... SCREENSHOTS: (And I use the 3DS browser sometimes...) NOTE: I have solved this on my own. But if you want to help, go to here.

Okay, let's start with this:
SPOFS X,y
X=NUMBER
Y=NUMBER
This is probably what needs to be done first, it'll make things easier, each level can have a different location by just inserting what X & Y equals. As for collision, don't use:
IF Y>145 THEN Y=145
Use the SPHITSP command for the tiles and your player sprite.
IF SPHITSP PLAYER,BLOCK THEN...

Okay, let's start with this:
SPOFS X,y
X=NUMBER
Y=NUMBER
This is probably what needs to be done first, it'll make things easier, each level can have a different location by just inserting what X & Y equals. As for collision, don't use:
IF Y>145 THEN Y=145
Use the SPHITSP command for the tiles and your player sprite.
IF SPHITSP PLAYER,BLOCK THEN...
Ok, I'll try it soon. Thanks Cymreig. EDIT: And what are you trying to mean about Player, Block Then?

I don't know about jumping though, check a platformer on here.

I don't know about jumping though, check a platformer on here.
Ok, then.

If you think of Super Mario Bros. on the old NES, you will notice that the world is made out of blocks on a regular grid (like graph paper). Or as they say in programmer/math circles Axis Aligned rectangles. So, instead of checking if you are past a certain y coordinate, it would be better if you could instead have a big rectangle for the floor or other obstacles and a rectangle for your hero character and check if the rectangles overlap. If they do, you have a collision and should bump the player back until they don't collide anymore. Rectangles can be said to not collide if for two rectangles A, and B, the left side of rectangle A is past the right side of rectangle B, or the bottom of Rectangle A is above the top of rectangle B, or if the top of rectangle A is below the bottom of rectangle B or if the right side of Rectangle A is before the left side of Rectangle B. If all of the not intersecting tests fail then they are colliding/intersecting. See: https://stackoverflow.com/questions/13390333/two-rectangles-intersection/44120056#44120056 You can get some help from smileBasic since background tiles and sprites are largely 16x16 pixels (there is a way to query Sprite size and location too). The background tiles are on a regular grid so you only need to check for tiles your player can actually touch say a 3x3ish grid starting at floor(player x / 16), floor(player y / 16) converting the players top left to tile coordinates and going to the tile coordinates matching their bottom right. Also only checking if a given tile is one you consider a solid block. That way you can design a level with data instead of hard coding boundaries. Hopefully that helps

If you think of Super Mario Bros. on the old NES, you will notice that the world is made out of blocks on a regular grid (like graph paper). Or as they say in programmer/math circles Axis Aligned rectangles. So, instead of checking if you are past a certain y coordinate, it would be better if you could instead have a big rectangle for the floor or other obstacles and a rectangle for your hero character and check if the rectangles overlap. If they do, you have a collision and should bump the player back until they don't collide anymore. Rectangles can be said to not collide if for two rectangles A, and B, the left side of rectangle A is past the right side of rectangle B, or the bottom of Rectangle A is above the top of rectangle B, or if the top of rectangle A is below the bottom of rectangle B or if the right side of Rectangle A is before the left side of Rectangle B. If all of the not intersecting tests fail then they are colliding/intersecting. See: https://stackoverflow.com/questions/13390333/two-rectangles-intersection/44120056#44120056 You can get some help from smileBasic since background tiles and sprites are largely 16x16 pixels (there is a way to query Sprite size and location too). The background tiles are on a regular grid so you only need to check for tiles your player can actually touch say a 3x3ish grid starting at floor(player x / 16), floor(player y / 16) converting the players top left to tile coordinates and going to the tile coordinates matching their bottom right. Also only checking if a given tile is one you consider a solid block. That way you can design a level with data instead of hard coding boundaries. Hopefully that helps
...Still I can't understand...

Okay, let's start with this:
SPOFS X,y
X=NUMBER
Y=NUMBER
This is probably what needs to be done first, it'll make things easier, each level can have a different location by just inserting what X & Y equals. As for collision, don't use:
IF Y>145 THEN Y=145
Use the SPHITSP command for the tiles and your player sprite.
IF SPHITSP PLAYER,BLOCK THEN...
Ok, I'll try it soon. Thanks Cymreig. EDIT: And what are you trying to mean about Player, Block Then?
If the sprites (tile and Player) collide, then make some code to keep the player on top the block.

If you think of Super Mario Bros. on the old NES, you will notice that the world is made out of blocks on a regular grid (like graph paper). Or as they say in programmer/math circles Axis Aligned rectangles. So, instead of checking if you are past a certain y coordinate, it would be better if you could instead have a big rectangle for the floor or other obstacles and a rectangle for your hero character and check if the rectangles overlap. If they do, you have a collision and should bump the player back until they don't collide anymore. Rectangles can be said to not collide if for two rectangles A, and B, the left side of rectangle A is past the right side of rectangle B, or the bottom of Rectangle A is above the top of rectangle B, or if the top of rectangle A is below the bottom of rectangle B or if the right side of Rectangle A is before the left side of Rectangle B. If all of the not intersecting tests fail then they are colliding/intersecting. See: https://stackoverflow.com/questions/13390333/two-rectangles-intersection/44120056#44120056 You can get some help from smileBasic since background tiles and sprites are largely 16x16 pixels (there is a way to query Sprite size and location too). The background tiles are on a regular grid so you only need to check for tiles your player can actually touch say a 3x3ish grid starting at floor(player x / 16), floor(player y / 16) converting the players top left to tile coordinates and going to the tile coordinates matching their bottom right. Also only checking if a given tile is one you consider a solid block. That way you can design a level with data instead of hard coding boundaries. Hopefully that helps
...Still I can't understand...
Basically use data like map arrays and the DATA command/stored DAT files you make to make maps and collision, instead of putting in coordinates you can't go to. It's much easier and WAY less tedious. Trust me, I made the mistake of doing that and it didn't go well...

Maybe I need to do that platformer tutorial after all. Would it be better if I did it in SmileBasic for 3DS or Switch?

Maybe I need to do that platformer tutorial after all. Would it be better if I did it in SmileBasic for 3DS or Switch?
I would say 3ds just because I have no Switch :( Or maybe both if you can? But idk...

Maybe I need to do that platformer tutorial after all. Would it be better if I did it in SmileBasic for 3DS or Switch?
I think 3DS is the better choise. (Until to the relase of the Switch-Version in other Countrys. ; Btw. the EU-3DS version was only released after 2.5 years after the japan release.)

Maybe I need to do that platformer tutorial after all. Would it be better if I did it in SmileBasic for 3DS or Switch?
I think 3DS is the better choise. (Until to the relase of the Switch-Version in other Countrys. ; Btw. the EU-3DS version was only released after 2.5 years after the japan release.)
Off topic...

Maybe I need to do that platformer tutorial after all. Would it be better if I did it in SmileBasic for 3DS or Switch?
I think 3DS is the better choise. (Until to the relase of the Switch-Version in other Countrys. ; Btw. the EU-3DS version was only released after 2.5 years after the japan release.)
Off topic...
no not off topic. It is connected to the topic because he is talking about a platformer tutorial seggiepants might make, which you might need as a solution or just a resource in general.

Maybe I need to do that platformer tutorial after all. Would it be better if I did it in SmileBasic for 3DS or Switch?
I think 3DS is the better choise. (Until to the relase of the Switch-Version in other Countrys. ; Btw. the EU-3DS version was only released after 2.5 years after the japan release.)
Off topic...
no not off topic. It is connected to the topic because he is talking about a platformer tutorial seggiepants might make, which you might need as a solution or just a resource in general.
Oh, then I should try to use off topic WHEN off topic themes are incoming.