This tutorial will show you how to have a character crouch, perform a crouched dash-slide, remain crouched even if the ↓ button is released when the character is underneath a crawlspace, and all of this works in reverse gravity too.
Setup Platform Character
We will be using a player container with pinned animations, as is standard with platformer games.
Here is our character positioned over a separate fucia container object:
Now we lay them directly over the top of each other:
Pin the character to the box:
The box has gravity normal and (a redundant) flipped anim, as well as crouch normal and flipped.
The only thing that changes is the collision polygon, the origin stays exactly the same for all states of crouch/gravity (important).
Animations and Preliminary Stuff
Take care of character mirroring:
And some anims:
This ternary operation:
...checks if our player is (in this case not) underneath an obstacle. If our gravity if switched, check ("down" relative to us, but "above" our character's head) down 20px for an overlap, or up -20px if gravity is normal.
Crawling and Crouching
This sets the ducking player animations and our crawling speed:
The last condition checks if we are on ground and restores the walk speed.
This is a test for the state of gravity according to the playerobject's collision box animation:
This sets more animations for the player and restores our walking speed if we're not crouching anymore:
Setting the crouch animations (and keeping us crouched even if we release the ↓ key when underneath an obstacle:
Again, more animations and ways to check we are able to stand if we are not underneath an obstacle:
Here are our ways of calling the slide function:
And here are the left and right slide functions:
Notice how if the character decelerates to the crawl speed, we keep on crawling at that speed rather than decelerating any further.
Here are our jump conditions, but we don't jump if we are underneath an obstacle, rather the slide conditions will take care of that (this is for both states of gravity) and also to keep jumping if space is pressed when we land:
Here are our gravity object collision animations and player animation conditions. It also takes care of all of the gravity changes and returns to normal after a predetermined time:
And that's it, have fun!