Diagonal Jump not working
void Update()
{
if (!CanMoveOrInteract())
{
horizontalValue = 0;
return;
}
//Store the horizontal value
horizontalValue = Input.GetAxisRaw("Horizontal");
//If LShift is clicked enable isRunning
if (Input.GetKeyDown(KeyCode.LeftShift))
isRunning = true;
//If LShift is released disable isRunning
if (Input.GetKeyUp(KeyCode.LeftShift))
isRunning = false;
//If we press Jump button enable jump
if (Input.GetButtonDown("Jump"))
Jump();
//If we press Crouch button enable crouch
if (Input.GetButtonDown("Crouch"))
isCrouching = true;
//Otherwise disable it
else if (Input.GetButtonUp("Crouch"))
isCrouching = false;
if (Input.GetKeyDown(KeyCode.Return))
animator.SetBool("Shoot", true);
else if (Input.GetKeyUp(KeyCode.Return))
animator.SetBool("Shoot", false);
//Set the yVelocity Value
animator.SetFloat("yVelocity", rb2d.velocity.y);
//Check if we are touching a wall to slide on it
WallCheck();
}
void WallCheck()
{
//If we are a touching a wall
//and we are moving towards the wall
//and we are falling
//and we are not grounded
//Slide on the wall
if (Physics2D.OverlapCircle(wallCheckCollider.position, wallCheckRadius, wallLayer)
&& Mathf.Abs(horizontalValue) > 0
&& rb2d.velocity.y < 0
&& !isGrounded)
{
if (!isSliding)
{
availableJumps = totalJumps;
multipleJumps = false;
}
Vector2 v = rb2d.velocity;
v.y = -slideFactor;
rb2d.velocity = v;
isSliding = true;
if (Input.GetButtonDown("Jump"))
{
availableJumps--;
rb2d.velocity = new Vector2(-horizontalValue * jumpPower, jumpPower);
AudioManager.instance.PlaySFX("jump");
animator.SetBool("Jump", true);
}
}
else
{
isSliding = false;
}
}
Comment