My player can jump and stick on walls, but when he jumps again (wall jumps), he just goes straight upwards. No matter what I change the new Vector2 “x” value to
I tried to disable all other movement for 0.2 seconds when the player wall jumps at the top of the update function with a wall jump counter (It disables the entire update function/player movement until the counter <= 0).
Maybe this function isn’t working but I don’t know why. Maybe it’s the x value in the "if(isGrabbing) statement. Idk what the heck is happening, thanks anyone
Also this is my first project so feel free to spell it out.
Wall jumping/player movement code:
public Transform wallGrabPoint;
private bool canGrab, isGrabbing;
private float gravityStore;
public float wallJumpTime = .2f;
private float wallJumpCounter;
private Vector3 m_Velocity = Vector3.zero;
private bool m_FacingRight = true;
[SerializeField] private float m_JumpForce = 400f;
public float runSpeed = 40f;
void Start()
{
//wall jump stuff
gravityStore = rb.gravityScale;
}
void Update()
{
if(wallJumpCounter <= 0)
{
//handle wall jumping
canGrab = Physics2D.OverlapCircle(wallGrabPoint.position, .2f, m_WhatIsGround);
isGrabbing = false;
if(canGrab && !m_Grounded)
{
if((transform.localScale.x == 1f && Input.GetAxisRaw("Horizontal") > 0))
{
isGrabbing = true;
}
if((transform.localScale.x == 1f && Input.GetAxisRaw("Horizontal") < 0))
{
isGrabbing = true;
}
}
if(isGrabbing)
{
rb.gravityScale = 0f;
rb.velocity = Vector2.zero;
if(Input.GetButtonDown("Jump"))
{
wallJumpCounter = wallJumpTime;
rb.velocity = new Vector2(-Input.GetAxisRaw("Horizontal") * runSpeed, 20f);
rb.gravityScale = gravityStore;
isGrabbing = false;
}
} else{
rb.gravityScale = gravityStore;
}
horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;
//testing move for wall jump
//rb.velocity = new Vector2(Input.GetAxisRaw("Horizontal") * runSpeed, rb.velocity.y);
animator.SetFloat("Speed", Mathf.Abs(horizontalMove));
if (m_Grounded && (Input.GetButtonDown("Jump")))
{
jump = true;
animator.SetBool("IsJumping", true);
else
{
wallJumpCounter -= Time.deltaTime;
}
}