- Home /
Inconsistent wallJumping, vector sends in wrong direction
Hello,
I'm trying to add walljump to my game, but my walljumps are very inconsistent for a reason I can't find :
illustration of the issue https://i.imgur.com/cCvlVZ0.gif
According to the debug those are the if that are called :
if (isTouchingWallRight && canWallJumpRight) //Used for a walljump from the right
{
canWallJumpRight = false;
canWallJumpLeft = true;
canControlJump = false;
rb.velocity = new Vector2(0, 0);
Vector2 forceToAdd = new Vector2(wallJumpForce * -wallJumpDirection.x, wallJumpForce * wallJumpDirection.y);
rb.AddForce(forceToAdd, ForceMode2D.Impulse);
Debug.DrawLine(transform.position, forceToAdd, Color.white, 2.5f);
Debug.LogError("WallJumpRight");
Invoke("ResetWallJump", wallJumpCooldown);
}
else if (isTouchingWallLeft && canWallJumpLeft) //Used for a walljump from the left
{
canWallJumpRight = true;
canWallJumpLeft = false;
canControlJump = false;
rb.velocity = new Vector2(0, 0);
Vector2 forceToAdd = new Vector2(wallJumpForce * wallJumpDirection.x, wallJumpForce * wallJumpDirection.y);
rb.AddForce(forceToAdd, ForceMode2D.Impulse);
Debug.DrawLine(transform.position, forceToAdd, Color.white, 2.5f);
Debug.LogError("WallJumpLeft");
Invoke("ResetWallJump", wallJumpCooldown);
}
You can see the debug whitelines that are drawn when a walljump is done. As you can see, sometimes a walljump from the right will send the player correctly to left, sometimes it will only launch into the air repeatedly.
My theory is, that's a physics issue (maybe I'm wrong !), so does anyone had a similar issue or have an idea of why it's like that ?
PS : if someone needs to have a deeper look into the script, you can check here : https://hastebin.com/ubevejuxaw.cs
Your answer
Follow this Question
Related Questions
how do i keep a gameobject in between the union of 2 or more than 2 circles 0 Answers
how come object is moving when i pressed nothing? 2 Answers
Access 2 of the 3 components of Vector3 (Vector3.xy?) 2 Answers
What is the kEpsilon field on Vectors? 2 Answers
Physics2D.Raycast "Vector3 to Vector2 conversion" [Solved] 1 Answer