[Solved] Crouching ok, but stay crouched?

Hi there!
I’m new to GameDev and had a good time on YT learning some cool things of GDev. Now i have soooo many questions, but step by step.

I work with a Player for the Animations (Gunnar) and for now with 2 Hitboxes (Character and Weapon). I managed to get my Gunnar in a crouching position to go under boxes. If he stands, he can´t. Thats ok. But if he is crouching under the boxes and i release the DOWN-Button, he glitches from crouching to standing and back again in a hyperfast loop.

How to avoid this "glitch"loop? I want to check first: If HitboxPoint(Head for example) is in collision with box, stay down Gunnar!

Can you try something like “if the Player’s Y coordinate is higher than the bottom of the box (and possibly also in collision with the box), change the animation to crouching”?

1 Like

I would recommend you try using an FSM (Finite State Machine).

An FSM is basically a system where you define some overall states for your object, and define the conditions for changing states and actions for that state for each state. It is good for you because as each state defines its exit conditions, you can just make the exit conditions for your case a bit more strict.

For this game, you could have 3 states: “idle”, “ducken”, and “laufen”. It would look approximately like this:

As you can see I added for the “ducken” state I added to the exit condition that you have to not be colliding with the Obstacle.

Though, you might not be in collision as you can crouch under them. Ideally, you would use another object as hitbox that has the size of the IDLE animation.

You can also try to change the code this way:


This code is switching for a short time to the “idle” animation to use the hitboxes of that animation, then switching back to the ducken animation if the exit consition is not satisfied, and if it is it will change the state. This would likely have unintended consequences though and I therefore recommend against this solution.

2 Likes

Thank you und thanks to beanmatt!
Cant wait to try it!

I will post my results.

So sorry, i did it for all my “States”, but it had no effect. Same issue again.

any other ideas?

I have this 2 animations for PlayerHitBox.
Animation 1 is for standing, walking, jumping etc.
Animation 2 is for crouching. (it’s Hitbox is smaller in height)

At Animation 2 I added a Point named “Kopf” above the Hitbox to check if its in collision witch the group “Plattformen”.

No matter what i do, it the same result.

to check if my collision PointX and Y “Kopf” of animation2 of Playerhitbox is set correctly, i added some Text.

It works.

But my Problem is still there.

SOLVED!!!

… and i don`t know why…

i changed the check :
If Point “Head” is in collision with an obj, stay crouched!
to
if PlayerhitBox ist in collision witch an obj, stay crouched!

that works.

As you can see in the textbox in the video, the Point “Head” worked perfectly, so i really don`t know why it know is working.

1 Like

I am glad you got it to work! Closing the topic as solved.

1 Like

Solved