Hello, I need help. I have no idea how to fix this bug. The bug is every time I tried to do a wall jump it doesn’t let me do, but when I do wall jump while grabbing or the position I jumped is next to wall it works. This is the code * `
private Rigidbody2D rb;
public float speed = 10;
public float jumpForce;
public float slideSpeed;
public float wallJumpLerp = 10;
public float dashSpeed = 20;
private Collision col;
public bool canMove;
public bool wallGrab;
public bool wallJumped;
public bool wallSlided;
public bool isDashing;
public int side = 1;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
col = GetComponent<Collision>();
}
// Update is called once per frame
void Update()
{
if (col.onGround)
{
wallJumped = false;
}
float x = Input.GetAxis("Horizontal");
float y = Input.GetAxis("Vertical");
Vector2 dir = new Vector2(x, y);
Walk(dir);
wallGrab = col.onWall && Input.GetKey(KeyCode.LeftShift);
if(wallGrab) {
rb.velocity = new Vector2(rb.velocity.x, y * speed);
}
if(col.onWall && !col.onGround) {
if(x != 0 && !wallGrab) {
wallSlide();
}
}
if(Input.GetButtonDown("Jump")) {
if(col.onGround)
{
Jump(Vector2.up, false);
}
if(col.onWall && !col.onGround)
{
wallJump();
}
}
}
private void wallSlide() {
rb.velocity = new Vector2(rb.velocity.x, -slideSpeed);
}
private void Walk(Vector2 dir) {
if(!canMove)
return;
if(wallGrab)
return;
if(!wallJumped) {
rb.velocity = (new Vector2(dir.x * speed, rb.velocity.y));
} else{
rb.velocity = Vector2.Lerp(rb.velocity, (new Vector2(dir.x * speed, rb.velocity.y)), .5f * Time
.deltaTime);
}
}
private void Jump(Vector2 dir, bool wall) {
rb.velocity = new Vector2(rb.velocity.x, 0);
rb.velocity += dir * jumpForce;
}
private void wallJump() {
StartCoroutine(DisableMovement(0));
StartCoroutine(DisableMovement(.1f));
Vector2 wallDir = col.onRightWall ? Vector2.left : Vector2.right;
Jump((Vector2.up / 1.5f + wallDir / 1.5f), true);
wallJumped = true;
}
IEnumerator DisableMovement(float time)
{
canMove = false;
yield return new WaitForSeconds(time);
canMove = true;
}`
I know this may be confusing but I need help. And anyone who wants to check the video here is the link : Recreating Celeste's Movement | Mix and Jam - YouTube