Hello! I am not sure if this is the right place to ask but I am a beginner at using Unity and I am working on a First Person Shooter. I currently have some problems with the jumping mechanics of the game. It seems to work but there is this bug that whenever the player runs into another object (let’s say a wall) they are unable to jump against the wall. However when they jump towards the wall and collides with it whilst mid air they are able to jump against the wall.
Just to check I understand that: are you saying that if the player is stood on the ground against a wall, they should still be able to jump vertically upwards but are not able to do so?
Assuming my understanding is correct, I think the problem could be that being in contact with a wall (which presumably does not have the “Ground” tag) means that Grounded will be set to false preventing the jump.
If I could make a few other observations about the code:
In this case prefer OnCollisionEnter and OnCollisionExit to OnCoillsionStay. There is no need to perform the check you are doing every frame.
When checking a bool, it is sufficient to say if(Grounded) rather than if(Grounded == true).
I haven’t tested this code (and rb obviously needs setting), but maybe something along these lines may help? One possible problem here is if you have multiple ground colliders in close proximity, you may want to consider changing m_grounded from a “bool” to a reference-counting “int” :-