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))
{
rigidbody.AddForce(0,-7,0);
}
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);
rigidbody.AddForce(0,-5,0);
}