Hey, whenever I hold up or down on the left stick, it moves my character to the left or right slowly as it would with variable movement on the X axis of the stick, which I don’t want. Because of this, you can move at extremely slow speeds, and go up walls without going out (The player just barely pops out from the wall and slides up the side) I have put in a Default Deadzone Min of 0.2, which works perfectly for left and right movement, but is ignored when holding the stick up or down. This is my first ever Unity project, so sorry if this is an obvious fix.
//Moving
public float speed;
private bool isFacingRight = true;
public float inputX;
public float inputY;
//Jumping
public float jumpForce;
public bool isGrounded;
public Transform groundCheck;
public float checkRadius;
public float fall;
public LayerMask whatIsGround;
private float slowOnce = 1;
//Walls
private bool isTouchingWall;
public float wallCheckDistance;
public Transform wallCheck;
public bool isWallSliding;
public float wallSlidingSpeed;
//Wall Jumping
public bool isWallJumping;
public float xWallForce;
public float yWallForce;
public float wallJumpTime;
//Dash
public bool isDashing;
public float dashForce;
public float isDashingCooldown;
public float dashStopTime;
private bool canDash = true;
public float canDashCooldownTime;
public float afterDashSpeed;
PlayerControls controls;
public SpriteRenderer sr;
public Rigidbody2D rb;
void Awake()
{
controls = new PlayerControls();
}
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
public void Move(InputAction.CallbackContext context)
{
inputX = context.ReadValue<Vector2>().x;
inputY = context.ReadValue<Vector2>().y;
}
public void Jump(InputAction.CallbackContext context)
{
if (context.performed && isGrounded && !isWallSliding && !isDashing)
{
rb.velocity = new Vector2(rb.velocity.x, jumpForce);
}
//Wall Jumping
if (context.performed && !isGrounded && isWallSliding && !isDashing)
{
isWallJumping = true;
Invoke("wallJumpingFalse", wallJumpTime);
}
if (isWallJumping)
{
rb.velocity = new Vector2(xWallForce * -inputX, yWallForce);
}
if (context.canceled && slowOnce == 1 && rb.velocity.y > 0 && !isGrounded && canDash)
{
rb.velocity = new Vector2(rb.velocity.x, -fall);
slowOnce--;
}
if (isGrounded || isTouchingWall)
{
slowOnce = 1;
}
}
//Is the player walljumping
void wallJumpingFalse()
{
isWallJumping = false;
}
public void Dash(InputAction.CallbackContext context)
{
if (context.performed && canDash && !isDashing)
{
isDashing = true;
canDash = false;
Invoke("stopDash", isDashingCooldown);
Invoke("canDashCooldown", canDashCooldownTime);
}
if (isDashing && isFacingRight)
{
rb.velocity = new Vector2(dashForce, 0);
Invoke("stopDash", dashStopTime);
}
if(isDashing && !isFacingRight)
{
rb.velocity = new Vector2(-dashForce, 0);
Invoke("stopDash", dashStopTime);
}
}
void stopDash()
{
isDashing = false;
rb.velocity = new Vector2(0, rb.velocity.y);
}
void canDashCooldown()
{
canDash = true;
}
void dashingFalse()
{
isDashing = false;
}
void Update()
{
//Left and Right Movement
if (!isWallJumping && !isDashing && canDash)
{
rb.velocity = new Vector2(inputX * speed, rb.velocity.y);
}
else if(!isWallJumping && !isDashing && !canDash)
{
rb.velocity = new Vector2(inputX * afterDashSpeed, rb.velocity.y);
}
//Check if Wall Sliding
if (isTouchingWall && !isGrounded && inputX != 0)
{
isWallSliding = true;
}
else
{
isWallSliding = false;
}
//Wall Slide
if (isWallSliding)
{
if (rb.velocity.y < -wallSlidingSpeed)
{
rb.velocity = new Vector2(rb.velocity.x, -wallSlidingSpeed);
}
}
}
void Flip()
{
isFacingRight = !isFacingRight;
transform.Rotate(0.0f, 180.0f, 0.0f);
}
void FixedUpdate()
{
//Flip character in right direction
if (isFacingRight && inputX < -.5)
{
Flip();
}
else if (!isFacingRight && inputX > .5)
{
Flip();
}
//Checks
isGrounded = Physics2D.OverlapCircle(groundCheck.position, checkRadius, whatIsGround);
isTouchingWall = Physics2D.Raycast(wallCheck.position, transform.right, wallCheckDistance, whatIsGround);
}
private void OnDrawGizmos()
{
Gizmos.DrawLine(wallCheck.position, new UnityEngine.Vector3(wallCheck.position.x + wallCheckDistance, wallCheck.position.y, wallCheck.position.z));
}
void OnEnable()
{
controls.Gameplay.Enable();
}
void OnDisable()
{
controls.Gameplay.Disable();
}
}