Wall Jump works, BUT not perfectly (advanced question)

Hello guys! This is a real mindbender.

My wall jump works ALMOST perfectly.

It’s just that since i’m holding “move right”, my hero keeps SUCKING RIGHT BACK INTO THE WALL >:E I can hence wallclimb my way to the top easilly, and this is not what I intended :smiley:

The only way to make my wall jump work (like a ping pong) is if I release my movement keys and keep hitting space.

It’s the only way to guarantee that my hero wont get stuck. It doesn’t feel right too me. I want the player to kind of press left+jump → right+jump → left+jump → etc… and really feel they are performing the wall jumps. Any suggestions on how to solve this? Maybe modify the controls IF touching a wall?

Here’s my working code:

		if (touchingWall && Input.GetButtonDown ("Jump") && !grounded)
			wallJump = true;

And then

				if (wallJump) {
					Vector2 vel = rigidbody2D.velocity;
					vel.y = 0;
					vel.x = 0;
					rigidbody2D.velocity = vel;
					// walljump right or left
					if (facingRight)
						rigidbody2D.AddForce (new Vector2 (-jumpPushForce, wallJumpForce));
					if (!facingRight)
						rigidbody2D.AddForce (new Vector2 (jumpPushForce, wallJumpForce));
					Flip ();
					wallJump = false;

Maybe reduce your in-air movement amount, so the player can’t “suck” back to the wall. And increase the jumpPushForce?

Another Option: Don’t allow the player to jump against the same wall twice in a row using a boolean.

if (lastWallJumpWasRight) allowWallJumpLeft();

Simply stop your input allowing character movement once grounded is false. This will prevent your character changing direction mid air.