[4.5.X] Quick tutorial: Adding the "skip top object collision" flag to use when crouching

dale_coop

Moderator
Staff member
Here's a small piece of code to modify the object collision box, to use when crouching (to avoid bats, projectiles, lasers, ... any monsters)

This is just an example, feel free to modify it for your needs...


1) In the "Project Setting > Project Labels", change the last "Monster Action Step Flag" to "Skip top object collision":

2021-07-28-08-37-12-Project-Settings.png



2) In the "Project Setting > Script Settings", under "SuRoutines", modify the "Handle Object Collision" script (I suggest to duplicate it and assign that duplicated one instead of the original)
At the beginning of that script, around the beginning (between line 50 to 75 depending of the module used) you will find the lines :
Code:
    TYA
    PHA
Before those lines, add this block of code:
Code:
    ;; dale coop, skip top object collision
    LDA Object_vulnerability,x
    AND #%10000000
    BEQ +skip
        LDA self_bottom
        SEC
        SBC self_top
        LSR
        CLC
        ADC bounds_top
        STA bounds_top
    +skip:

You should now have a script that looks like that:

2021-07-28-08-46-23-do-Handle-Object-Collisions-Platformer-Base-asm-Visual-Studio-Code.png



3) Modify your Player's action step (the one you used for "crouch") and set the "Skip top object collision" flag:

2021-07-28-08-40-40-Monster-Animation-Info.png


4) I think this step you may have already done it, but... now, I will just add an input script to my HOLD Down button. Script that will just change my player to his courting state (action step 4, in my case).
My "crouch.asm" input script looks like that:
Code:
    TXA
    STA temp ;; assumes the object we want to move is in x.
    ChangeActionStep temp, #$04
    RTS
...and is assigned to my HOLD Down button:

2021-07-28-08-50-28-NES-MAKER-4-5-9-Version-0x176-Arcade-Platformer-Tutorial-MST.png


VoilĂ , now you should be able to skip your enemie's projectiles.
 
Last edited:

vanderblade

Active member
Hey @dale_coop. This works great, but I was wondering if you knew a way to extend this logic to tile collisions. I have a player character that can duck and then slide along the ground. But right now, the ducking doesn't halve the hit box for tile collisions the way it does for other object collisions, like monsters and projectiles. Could something similar to this be set up in the tile collisions script, for instance? So you could crawl or slide along the ground in a space only one tile high?
 

dale_coop

Moderator
Staff member
Hey @dale_coop. This works great, but I was wondering if you knew a way to extend this logic to tile collisions. I have a player character that can duck and then slide along the ground. But right now, the ducking doesn't halve the hit box for tile collisions the way it does for other object collisions, like monsters and projectiles. Could something similar to this be set up in the tile collisions script, for instance? So you could crawl or slide along the ground in a space only one tile high?
But the logic would be more complicated... because you will have to prevent to get back to a non "skip top collision" else your player will finished suck in a wall ;)
(it's the reason why I didn't went further in that... it would cause too many issues in the projects and people will get lost trying to fix that)
 

vanderblade

Active member
But the logic would be more complicated... because you will have to prevent to get back to a non "skip top collision" else your player will finished suck in a wall ;)
(it's the reason why I didn't went further in that... it would cause too many issues in the projects and people will get lost trying to fix that)
All good points. I may just create projectile corridors that force players to make use of the crouching rocket dash instead. :)
 

dale_coop

Moderator
Staff member
Would this script work on Metroidavania?

I think it should work... the only difference would be the line numbers from my tutorial might not be exactly the same, you will have to find where to place the code.
 

zero

New member
It's a cool way!
I did this but from a different script. I decided to change Bouting Box when crouch mode is ON.
File => doHandlePhysics_PlatformBase.asm, line 140
Once BoutingBox is decreased my player can pass, or do a slide, and on a final Action (ChangeActionStoStop_UnlessJumping.asm) i change "canCrouch=0"
; Decrease the bounting Box when canCrouch is active

LDA canCrouch ;if value = 1
BNE +decBbox
JMP +doNothing
+decBbox
LDA BboxL ;var of new left value
STA self_left
CLC
ADC BboxW ;var of new width value
STA self_right
SEC
SBC self_left
LSR
STA self_center_x

LDA BboxT ;var of new top value
STA self_top
CLC
ADC BboxH ;var of new heigh value
STA self_bottom
SEC
SBC self_top
LSR
STA self_center_y ;; self center in the vertical direction.
JMP +continue
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

+doNothing
LDA ObjectBboxLeft,y
STA self_left
CLC
ADC ObjectWidth,y
STA self_right
SEC
SBC self_left
LSR
STA self_center_x

LDA ObjectBboxTop,y
STA self_top
CLC
ADC ObjectHeight,y
STA self_bottom
SEC
SBC self_top
LSR
STA self_center_y ;; self center in the vertical direction.

+continue
 

zero

New member
Hey guys i'm trying to use this code to go under the wall but it works only against monsters.
I tryed to decrease some BountingBox values on DoHandlePhysics but it dos not work well, i have a lot of bugs doing this.
I tryed to configure "collisionsToCheck" but i had no success.
Any tip?

test.gif
 

Barry2

Member
Hey guys i'm trying to use this code to go under the wall but it works only against monsters.
I tryed to decrease some BountingBox values on DoHandlePhysics but it dos not work well, i have a lot of bugs doing this.
I tryed to configure "collisionsToCheck" but i had no success.
Any tip?

View attachment 5968
This is a really good idea! Ill be following this
 

SciNEStist

Well-known member
But the logic would be more complicated... because you will have to prevent to get back to a non "skip top collision" else your player will finished suck in a wall ;)
(it's the reason why I didn't went further in that... it would cause too many issues in the projects and people will get lost trying to fix that)
I guess that's why the Mario games always pushed a player to the right whenever stuck inside a block
 

zero

New member
All right this is getting interesting! i've done passing under the wall but player stops on collision.
The player should not stand under the wall untill pass. I dont know how to fix this, i'm searching a solution

test2.gif
 

SciNEStist

Well-known member
Honestly, that seems pretty acceptable, as long as you can unstick yourself.

if it HAS to be fixed, you can disabling uncrouching if there is a collision above you, and add something to the left and right movement. that would probably be the smoothest
something like:
>is player crouched?
>if so, is the player still holding the crouch button?
> if not, is there room above the player?
>if so, then change to not crouching


doing it something like this would mean if you take your hand of the down arrow, itll stay crouched until you are free.
 

zero

New member
CheckCollisionPoint is what you would need. Something similar to what is seen in THIS thread (with some modifications)
Thankyou! That was very hellpfull!
I'm understood the logic for PrizeBlock Tile but i decide to use Hurt Tile to do make a tile that prevents player to stand up and it works well!!!
 

SciNEStist

Well-known member
I don't think you would need a special tile for it, you can just check if above the player is solid or not.
 
Top Bottom