Download

How can I disable my crouch action mapping temporarily?

I have a crouch system in place that crouches when the left mouse button is pressed and uncrouches when it’s released. Additionally, it checks to see if there is collision above the camera and if so, won’t uncrouch until there is no detection of collision. Everything works great, until the left mouse button is spammed which bypasses the rule of remaining in crouch. I want to effectively disable the action maping (left-click) while the player is underneath something and I’m having some trouble. I’ve done some research and based off of what I found I have an idea for how to do this, but when it came down to me doing it myself I messed up. I’ve attached two screenshots, one with my prior code and the other with what I added.

I know what the issue is here, just not how to get it working. I created a boolean called IsBelowSomething and have each pressed and released sent to a branch to see if it’s true or false. I’m pretty sure the way I have it currently, it’s always false. I thought by plugging the red execute from the LineTraceByChannel it would work just as it did before, only this time storing that result into a var that could then be used to get the state elsewhere.

Have you tried using a tick event for this? I have a linetrace thats called every frame that traces above the players head to their max height, and if it his something on the way, then it doesnt allow me to uncrouch by setting bCanCrouch to false and using a branch to detect the variable when using the crouch button.

Hey Shirk, thanks for the reply. I haven’t tried using that yet, although I did just increase my delay to .01 versus what it was previously at (.75) and I’m still able to spam the left click. You mention that it doesn’t allow you to uncrouch, but what happens when you spam your crouch button? My setup doesn’t allow my character to uncrouch either if I let go, only if I spam the left click. How would I setup this event tick to test? Sorry, I’m new to blueprints and programming in general.

Considering tick is ran every frame its variable, but generally for most people I would assume it would be 30fps, so the tick even is fired 30 times per second, most likely faster than the average gamer can spam click the uncrouch key. As for setting it up, you basically just move what you have for the line trace from your crouch even to the tick event, having it trace upwards every tick.

Well I think what I had was just like your event tick then, if not more often. I had a delay of .01 so it was running the line trace 100 times per second, unless 30fps is the maximum then it would be running at that. I ended up fixing the problem though and it was so simple! All I did was copy/paste all of my line trace stuff and plug my “pressed” into it the same way “released” was already set up. I’ve attached a screenshot in case anyone has a similar issue.