# Wall Jump Instead of Sliding up

I have a player script for my 2d platformer that when you touch a wall instead of wall jumping the player will just slide up the wall, how can I tweak the script in order to make my player formally wall jump?

Script:

using UnityEngine;
using System.Collections;

public class PlayerScript : MonoBehaviour {
public float speed = 500.0f;
public float JumpSpeed = 100.0f;
private bool isGrounded = false;
public float gravity = 20;
void Update()
{

``````//transform.position += new Vector3(Input.GetAxis("Horizontal"),0,0);
if(Input.GetKey(KeyCode.S))
{
}
if(Input.GetKey (KeyCode.A)){
transform.Translate(new Vector3(-1,0,0) * Time.deltaTime * speed);
}
if(Input.GetKey (KeyCode.D))
{
transform.Translate(new Vector3(1,0,0) * Time.deltaTime * speed);
}
if (isGrounded && Input.GetButton("Jump"))
Jump();
}
``````

void OnCollisionStay()
{

``````isGrounded = true;
``````

}

void Jump()
{
rigidbody.velocity = Vector3.zero;
rigidbody.angularVelocity = Vector3.zero;
isGrounded = false;

``````rigidbody.AddForce(Vector3.up *JumpSpeed);
``````

}

In my game, when the player jumps on a wall, I decrease gravity significantly, to give an effect of sliding down the wall.

In order to stop the wall sliding up, donâ€™t let an upward force be applied to the player if they are not grounded to the floor. If they are grounded to the wall, then make it so that when the player presses jump, a force opposite of the direction of the wall is applied so that the player is pushed away from the wall when they jump. At the same time, allow the player to make his way back to the wall.