jerky walljump in unity rigidbody2d
Posted
by
Lilz Votca Love
on Game Development
See other posts from Game Development
or by Lilz Votca Love
Published on 2014-05-25T19:35:01Z
Indexed on
2014/05/26
22:06 UTC
Read the original article
Hit count: 362
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
© Game Development or respective owner