jerky walljump in unity rigidbody2d
- by Lilz Votca Love
hey there i know people have encountered issues with it before i looked upon the different solutions provided but i couldnt get any fix at all.im making a 2d game and am stuck with the walljump.i detect the wall wonderfully i also detect the jump and it works the player jumps off the wall when facing right with the use of rigidbody.addforce(new vector2(-1,2)*jumpforce) now when jumping on the oposite wall using the same vector with the sign in x axis changed to 1,the player jumps too but it goes more in the y axis than it should.Here is an image to show you the curves it(the player) follows.
check the following url to see the behaviour https://scontent-b-mad.xx.fbcdn.net/hphotos-xpf1/t1.0-9/1470386_10152415957141154_156025539179003805_n.jpg
voila the green one is happennig when player faces right and the other one happens when he is not here is the section of code
if (wall)
{
if (wallJump)
{
if (facingRight)
{
rigidbody2D.velocity = Vector2.zero;
flip ();
rigidbody2D.AddForce (new Vector2 (-1f, 2f) * Jumpforce / 1.5f);
Debug.Log ("saut mural gauche" + new Vector2 (-1f, 2f) * Jumpforce / 1.5f);
}
else
{
rigidbody2D.velocity = Vector2.zero;
flip ();
rigidbody2D.AddForce (new Vector2 (1f, 2f) * Jumpforce / 1.5f);
Debug.Log ("saut mural droit--" + new Vector2 (Mathf.Sign (1f), 2f) * Jumpforce / 1.5f + "jump" + jump);
}
}
}
else
{
wallJump = false;
}
here the code is not optimized yet but i assure you it works so guys any help would be so awesome!! thanks