Why is my Jump Height affected by Walls?
My game's main character is using a rigidbody:
The player's physics material has zero friction because otherwise, jumping and steering against a wall would make the player stick to the wall.
Jumping is done by applying a large impulse to the character via
rigidbody.AddForce(..., ForceMode.Impulse)
.
Now when the player is very close to a wall (or steering into it), he can jump almost 50% higher:
Can someone explain this effect or offer a workaround?
Additional observation: this happens even if I jump from some distance to the wall and touch the wall on the way up. It seems touching walls either reduces the effects of gravity or increases momentum.
Answer by Cygon4 · Mar 20, 2013 at 12:53 PM
It took some searching, but I dug out another question here on UnityAnswers that provides a workaround:
Rigidbody Character Jumps Higher With At Least 2 Collisions
If I add a rigidbody to the wall (not just a collider) and enable its Is Kinematic
property, the jump height next to that specific wall remains constant, avoiding the issue.
There is still a big WTF hovering over my head, but I remember having read somewhere in the Unity documentation that any object that interacts with physics should have a rigidbody, so I guess this is a "by design" issue.
Officially, "static colliders" (collider with no RB) are for things that will never move. $$anonymous$$inematic colliders are supposed to be for special cases.
Clearly, "bouncing off me" isn't a special case (it's the primary purpose,) so something odd is going on. You'd think ken-RB vs non would make ALL collisions a little different (Y isn't a special axis.) Hmm...
Answer by Tanbar · Jan 18, 2019 at 04:25 PM
The Walls collider are tall thus when u jump(While hugging the wall) the Collider on the player still remains in contact thus Forces adds up making the jump more higher.
WORKAROUND
Simply make bool variable and make it true when in air and false on landing. and call the jump only when variable is false. ,Anyone facing this issue can just add bool variable which is true,when GameObject is in the air and false,when it lands.
This is based on the assumption that my jump logic is faulty and lets the character jump when it is touching a wall.
That was not the case here. It was a physics issue. A composite RigidBody collider sliding on a static non-RigidBody collider caused the simulation to behave differently.
But maybe this answer helps others who have more down-to-earth (hehe, get it?) problems with their jump logic :)