New Bug in Platform Code.

BlitzMax Forums/BlitzMax Beginners Area/New Bug in Platform Code.

Amon(Posted 2007) [#1]
While testing a map today I found a quirk in the platform code. Basically the character can walk across a gap without falling.



Run this example and you'll see. The CHaracter starts on a platform and when walking right walks over the gaps.

Is there a way to fix this?

Thanks.


Dabz(Posted 2007) [#2]
If map(mapX,mapY+1)= nothing
playerY = playerY + 1
doLeftandRight = false
end if

Though, it would be a good idea to stop them moving left or right (doLeftandRight) when falling, since they may end up floating through the walls.

I would go through you code, but my head is a shed with my own! :)


Amon(Posted 2007) [#3]
Thanks Dabz M8, will give it a go. :)

[edit] I think something similar is already in place. I just tried your method and it doesn't appear to work.

Here's what's in place already.

	If not Map[PlayerX / 32 + 1, PlayerY / 32 + 1]and not Map[PlayerX / 32, PlayerY / 32 + 1]
		If Jump = 0
			Falling = 1
		EndIf
	End If


I kind of need the player to move left and right when falling. It's oart of the game. I will have other types of tile though that when falling or jumping towards, stop the player in his tracks.

:)


Dabz(Posted 2007) [#4]
ahhh, it seems you are checking below AND across and below...

If not Map[(PlayerX / 32) + 1, (PlayerY / 32) + 1] and not Map[(PlayerX / 32, PlayerY / 32 + 1)]

So if theres one space, it still picks up the block further on, which means you wont fall! :)

Dabz


Amon(Posted 2007) [#5]
The thing is that's needed in order for the player to be able to move to the very edge of the tile and when he's past it he falls.

Is there a way to check for instance the outer edges of a tile on it's X axis.

ie if PLayerX is less than >=5 and less than <=27 then a collision is detected. If not he falls. That would fix the issue I think.

I never thought that platform collsion code could be this querky to sort out.

You see games like mario and wonder quite how they did it. :)


Grey Alien(Posted 2007) [#6]
yep platform collision code can have many problems. You wait until you add solid walls and ceilings you can hit your head on. Then slopes ... haha :-)

Why not try setting the new coords for the player when they move in a direction (keeping the old ones stored), then do a test for a tile on on both corners (and maybe the middle of the edge) in the direction they are moving. If a tile is detected, reset the coords. This will work for up/down/left/right etc. Also when falling, if you detect you have fallen "into" a tile, you can't just reset the y coord or you'll never land, you need to set the y coord so the player is perfectly on the tile and then change the player graphic to walking and play a landing sound.


Amon(Posted 2007) [#7]
Why not try setting the new coords for the player when they move in a direction (keeping the old ones stored), then do a test for a tile on on both corners (and maybe the middle of the edge) in the direction they are moving. If a tile is detected, reset the coords. This will work for up/down/left/right etc. Also when falling, if you detect you have fallen "into" a tile, you can't just reset the y coord or you'll never land, you need to set the y coord so the player is perfectly on the tile and then change the player graphic to walking and play a landing sound.


Can you show me some sample code?

Or can you have a look at the code above a provide some code?

Please. :)


Grey Alien(Posted 2007) [#8]
You got my email right? Look at the code for Make Me Happy. I'd love to help more but I'm crazy busy now after returning from 3 weeks of holidays.


Amon(Posted 2007) [#9]
I looked at the MakeMeHappy code. I couldn't figure out what you were doing. :)

While playing I noticed that you never had any tiles that were the same distance apart as the width of the character. They were furthere apart than this.

In the platform code above I have a tile, a space and a tile. The distance between them is exactly 32 pixels. This is the width of the player.

Becuase of bounds checking the player canb walk across this gap without falling.

Modifying the bounds checking borks up the whole collision code.

Can anyone else help?

:)


Jesse(Posted 2007) [#10]
here this is the best I can do with out rewritting your code:



it will not allways fall and it has to do with the 6.4 test being performed while still moving left or right. if you happen to stop moving at the exact end of the tile then it will fall, such is the case when reaching a wall. you can add a test to only accept movement input when not falling and this will allow falling allways. You can figure that out right?


Amon(Posted 2007) [#11]
Thanks Jesse. :)

Yep, when continually walking the player still walks across the gap.

When you said it's the best you could do without rewriting the code, what did you have in mind to rewrite?

You've been very helpful and if you could fix this with a rewrite I would appreciate it. :)

I have no idea what to try to fix this.


Grey Alien(Posted 2007) [#12]
Sorry my code wasn't of any help. Basically there are lots of ways to make a platformer and most have some complexity in there somewhere. In some ways you are better off figuring this issue out yourself for the experience points. Good luck!


Amon(Posted 2007) [#13]
Sorry my code wasn't of any help. Basically there are lots of ways to make a platformer and most have some complexity in there somewhere. In some ways you are better off figuring this issue out yourself for the experience points. Good luck!



You must have me confused with the amazing Amon. :)


Grey Alien(Posted 2007) [#14]
lol, well we all had to learn somehow. In my case it was on 8 bit computers 20+ years ago...I had to relearn a ton of new stuff though when using Blitz Plus and then even more for BMax!


Amon(Posted 2007) [#15]
This seems to work. :)




:)


Jesse(Posted 2007) [#16]
sorry, Amon. I guess I was being lazy when I said that. lazy to think some more.

your code seems to works fine now. I hope that's what you want. now, as long as you don't try to work with slopes and maps larger than screen size and moving at different speeds this should be good enough. is it? :)


Amon(Posted 2007) [#17]
your code seems to works fine now. I hope that's what you want. now, as long as you don't try to work with slopes and maps larger than screen size and moving at different speeds this should be good enough. is it? :)



It'll do for messing about. But not for a proper platformer.

This method I'm using which you guys have helped me with doesn't appear to be the best solution for making platform games.

It would be good for a game like BomberMan or a top down view sort of RPG but for platformers where there's jumping, falling ect it's not good.

I am eager to learn or to be showed different types of platform collision and setup.

You wouldn't happen to have any other methods for building a platformewr that didn't use tile checking in this way.


MGE(Posted 2007) [#18]
"The distance between them is exactly 32 pixels. This is the width of the player."

It's common practice to never have a gap in the tile map that equals the width of a player. If you want a player to fall into a 32 pixel wide gap, then the player should be 30 pixels or less. Making a 32 pixel wide player fall into a 32 pixel wide gap opens up a can of worms in the logic code. If your player is moving anything greater than 1 pixel per frame, think about the coding logistics in that scenario. ;)

Another trick commonly used, is to have a 32 pixel wide player but only code the tile collisions on the middle 30 pixels. This will let you fall into 32 pixel wide gaps easier, etc.


Grey Alien(Posted 2007) [#19]
Yeah it's worth having a smaller collision rectangle, although this may mean that you can walk up to a wall and a couple of pixels of the character are drawn in the wall. Mind you TONS of games have done that before so it's no big deal it's artistic licence.


Amon(Posted 2007) [#20]
Thanks Guys. I don't think of this stuff when I dive in to coding. It's one of my great failings. :)

You're right when you say that having a CHaracter the same size as a tile is going to cause problems and it has.

I'm going to try and fix it so that the character ius either 16 pixels wide or somewhere in the region of 25 to 30 pixels wide.

I'll post back when I've sussed it out. :)


Amon(Posted 2007) [#21]
HI, I've sorted it. The new code takes in to account the Player Width. Modify Player_Width to anything below say 28 and it will take care of the collision.

the Collision is based on the player being 16 pixels wide.

This now works well. It could do with more tweaking to perfect it but that's something I'll do later.

Here's the code.



I'd like to thank all who helped me get this working and for their patience.

Hopefully this code will help people with their platform games and help them learn as I did.

Big up to the BRL members. :)


Grey Alien(Posted 2007) [#22]
excellent! Now to make Super Amon Brothers.


Jesse(Posted 2007) [#23]
if you are interested in looking at a remake of Super Mario in blitzmax you can download it from here:
http://www.adam.com.au/therevills/Projects/Mario/Mario%20BlitzMax.exe

it includes working executable and source code minus graphics. it has advanced topics that you might not understand. But maybe it'll help you figure out some ideas on coding it differently.