implementing a wall jump
Hey folks, I'm trying to make a wall jump mechanic in 2D, so far I have the player clinging to the wall if I hold the directional button down, I want to press the jump button while I do that, and have it ignore the directional input and do the jump arc.
This is what I have so far:
void wallClingingFun()
{
rb2d.velocity = new Vector2(0, 0f);
wallCling = true;
doubleJump = true;
if (Input.GetButtonDown("Jump"))
{
wallCling = false;
if (facingRight)
{
facingRight = !facingRight;
rb2d.velocity = new Vector2(-25, 7);
wallJump = true;
}
else if (!facingRight)
{
facingRight = !facingRight;
rb2d.velocity = new Vector2(25, 7);
wallJump = true;
}
}
obviously, it's not working, and I'm not sure what the correct functions I should use to make it work.
Any ideas?
Answer by SwedishDerp · Feb 26, 2018 at 07:53 AM
Instead of using a 'velocity' function, try adding force to the rigidbody. When creating a basic jump function the 'AddForce' is commonly used :)
Example Script:
rb2d.Addforce(transform.right * 30, ForceMode.Force);
And when jumping left you just put a "-" before the "transform.right" to jump in the opposite direction :)
rb2d.Addforce(-transform.right * 10, ForceMode.Force);
This may or may not be a functional script but I suggest you google about adding force to a side direction and also experiment yourself!
Still the same problem, the character doesn't actually jump away from the wall when I press the jump button.
@Viredae,you want when the character collides with the wall,then he can jump or what?is it an endless runner?can you explain a little more or post a screenshot of your game.
I have the character clinging to the wall when I hold the directional input, and I want to press the jump button while clinging to have the character ignore the input and jump away from the wall.
A$$anonymous$$A a wall jump, it's not rocket science.
Your answer
Follow this Question
Related Questions
How could I add "gravity" to a top-down shooter's bullet, such as in The Binding of Isaac? 0 Answers
I can not get my character to crouch? Character not sliding on walls? 0 Answers
How to move upward with wall jump and not be pulled down too quickly? 0 Answers
I have a walljump script but the walljump doesn't work right can someone help me? 0 Answers