# Not able to make Wall Jump properly

I am trying to make my player jump from wall. I know I can do that by adding force in opposite direction. but my player is jumping weirdly and I tried to solve it by reading and watching tutorial but can't do it by myself. I think I need more professional and experienced mind to solve this.

I have 2 script one take care of wall jump and other script is responsible for movement and jump from ground and in this script i have applied if I pressed button longer player will jump higher.

This is the PlayerScript

public class PLayer : MonoBehaviour {

float input;
public float moveSpeed = 10;
bool jumpButtonPressed = false;

float startingMoveSpeed;
[Tooltip("move Speed when player jump")]
public float jumpMoveSpeedDecrementor = 3;
public float jumpForce = 10;
Rigidbody2D rgbd;
[HideInInspector]
public bool grounded,wallJump;
bool isJumping;

// Use this for initialization
void Start () {

startingMoveSpeed = moveSpeed;
wallJump = false;
}
private void Update()
{
if (!jumpButtonPressed)
{
jumpButtonPressed = Input.GetKeyDown(KeyCode.Z);
}

}
// Update is called once per frame
void FixedUpdate ()
{

//check if grounded or doing wall jump
if (grounded|| wallJump)
{
animator.SetFloat("horizontalSpeed", Mathf.Abs(input));
moveSpeed = startingMoveSpeed;
}
else
{//if in the air mean jumping
moveSpeed = jumpMoveSpeedDecrementor;
}

//if jump button press then jump
if (jumpButtonPressed && grounded )
{
isJumping = true;
animator.SetTrigger("jump");

jumpButtonPressed = false;
}

}
if (Input.GetKeyUp(KeyCode.Z))
{
isJumping = false;
}
}

}

This is the second script which take care of the wall jump.I have added physics material to the wall with 0.02f friction.

public class WallJump : MonoBehaviour {
PLayer player;
public float rayDistance;
public int speed = 20;
public int speedY=300;
// Use this for initialization
void Start () {
player = GetComponent<PLayer>();
}

// Update is called once per frame
void Update () {
//ray should not collide with the self
Physics2D.queriesStartInColliders= false;
//ray cast
RaycastHit2D hit = Physics2D.Raycast(transform.position,Vector2.right*transform.localScale.x, rayDistance);
//if hit wall and jump
if (Input.GetKeyDown(KeyCode.Z ) && !player.grounded && hit.collider.tag=="wall")
{
player.wallJump = true;
//add force in -X and y direction
//  GetComponent<PLayer>().flipUsingScale();
}
else
{
player.wallJump = false;
}

}
private void OnDrawGizmos()
{
Gizmos.color = Color.green;
Gizmos.DrawLine(transform.position, transform.position+ Vector3.right * transform.localScale.x * rayDistance);

}
}

Thank you for reading and helping immature programmer like me.