Wassup? It’s been awhile!
Sooooo, I’m trying to create what I call a Duck Area for my player.
In my game, the player has the ability to duck and skid. y’know, they can crouch when standing still and move left or right while in the crouched position.
I want to create a mechanic where the player will be in the crouch position when they’re touching an object. This way, the player won’t glitch out if I take my hands off the keys and they’re still under a solid object. That’s currently happening right now.
See those blue strips in the screenshot? When the player touches those, they’ll immediately duck. If the player is moving while touching the strip, then the player will skid. The player can still freely duck and skid outside of these areas when they press the right buttons.
Why don’t you just say that if the player is colliding with those, isDucking or whatever variable you have is forced on?
I have to build up the code first.
That’s gonna be my daily/weekly challenge.
This one didn’t work
What didn’t work
I noticed that the speed changed, as the player is supposed to slow down when crouching, but the animations and mesh didn’t. The player couldn’t duck or crawl under objects.
I also think that I might be confusing the programing a little or giving it conflicting directions. I was trying to link the code through the pressing of the Duck button.
PS- for anyone wondering, I set my keys to a global variable because I have a mechanic that allows players to change the buttons to control the player.
Getting warmer…
What’s working
So! When the player collides with the blue strip, the object variable will turn to true. The player will duck when it’s touching the strip and not moving, but will skid when it’s touching the strip and moving. This means that the player can crawl under objects without glitching out the second they stop pressing the duck key before they’re on the other side.
When the player isn’t touching the strip, but I have the duck button pressed down and moving, they will skid.
What’s not working
When I press the duck button and the player isn’t moving, they won’t duck.
Success
What I did
I had to separate the coding between the player touching the Duck Area and the key commands. I was hoping that I could link them all up with the object boolean, but that wasn’t working.
The player can now duck and skid by pressing the right keys. They can now automatically stay in the crouch position when touching the blue strip, even if the player takes their hand off the keys. They won’t leave the crouch position until they aren’t touching the strip. This is what I pretty much wanted.
I think this is very useful because I could change up this chuck of code to fit other purposes.
ONE MORE THING
I had to make sure that the Y collision points as well as the center points of the duck and skid animations were the same.