News:

Building a 3D Ray Tracer  By stevmjon

Main Menu

Help with platformer

Started by ScottieBro1, January 29, 2024, 11:53:05 AM

Previous topic - Next topic

Can someone please help clean code up

e-mail
0 (0%)
post
0 (0%)
reply
0 (0%)

Total Members Voted: 0

ScottieBro1

I was wondering if someone could help me figure out the collision detection for someing like this.
I need it tighter code not showing nicely.
Scottie B

Give a hack!
Thanks

stevmjon

with platformers there is actually 2 main worlds you can create, or you can manually create one like what you have done.
you can create worlds using PB inbuilt commands. they have cameras, layers etc that handle sprite sorting and tile map drawing. there is 2 main types of PB inbuilt worlds where one does the collision detection with tiles for you as well as collision with lines, or the other draws everything but you handle tile collision yourself. i use this second method, because you can make your own custom sloped tiles.

i recommend using the PB inbuilt worlds because you can put tiles and sprites (characters etc) on different layers and even scroll different layers at different speeds, which gives an effect of depth. so foreground moves faster and background moves slower.
i have a small demo on the forums you could check out for idea's. i think it was called 'sloped tiles'? i also made a bigger demo called 'holly'. you are welcome to use the graphics i made too.

anyway, i like looking at what you code and will take a peek.

  stevmjon
It's easy to start a program, but harder to finish it...

I think that means i am getting old and get side tracked too easy.

stevmjon

hey scott

just made an edit that smoothes out the left/right tile collision. you can now walk into a tile without it rubber banding left/right.
you will also need to put in a safety check before reading arrays to make sure player or tile you are checking in inside world bounds, so you don't read array outside it's dimension (gives an error message).

keep growing the platformer.

  stevmjon
It's easy to start a program, but harder to finish it...

I think that means i am getting old and get side tracked too easy.

kevin


  There's various 2d platformer examples posted and even a few in the PLayBASIC examples..  But here's the Mario demo from 2009

  Mario Demo

 


kevin

#4
 I think with these type of collisions it best to step through the possibles then  choose the best option.  in sliding collision recursion is generally used so be find the first collider (if any) then compute the re-positioned (slid) movement vector..  Then repeat this process until no collisions occur.

It's worth trying to handle as there's always situation were a character will slide through wall / corner given the right circumstances.   Speed runners love those kinds of bugs, but players hate them.