I am in the process of creating movement for my player that can only move on the x and y axis, I decided to make it a 3D game because I've been trying to learn that dimension of games. My movement functions are set up as so:
public void playerMovement()
{
horizontalInput = (int)Input.GetAxisRaw("Horizontal");
if (horizontalInput != 0)
{
moveX = Mathf.MoveTowards(moveX, horizontalInput * speed, Time.deltaTime * acceleration);
} else
{
moveX = Mathf.MoveTowards(moveX, horizontalInput * speed, Time.deltaTime * acceleration * 4f);
}
rb.velocity = new Vector3(moveX, rb.velocity.y, 0);
grounded = Physics.CheckSphere(groundCheck.transform.position, .2f, LayerMask.GetMask("Ground"));
if (Input.GetKeyDown(KeyCode.UpArrow))
{
Jump();
}
}
public void Jump()
{
if (grounded)
{
rb.velocity = new Vector3(rb.velocity.x, jumpSpeed, 0);
}
}
I am using this code from a tutorial I found on Tiktok and everything works well in the update function, however, when I collide with a wall or the side of any of my objects, I stop in place and can't fall back down. I also can't move out of the area very fast, it takes about 3 seconds to move out of there(I predict from my acceleration slowing down and turning around). Is there a reason I am stuck on the wall once I collide?