I have a 3D animated player, I am using a rigidbody and a capsule collider.
Once I jump and move towards the side of the platform, my player just gets stuck. I tried looking for solutions, I found one solution which works for me.
if (!isGrounded() && Mathf.Abs(move) > 0.01f) return;
This stops my player from sticking to the wall. However, if the player gets right to the edge of the platform, he cant move.
My player control script
public float runSpeed = 8f;
public float jumpHeight = 8f;
float force = 25f;
Rigidbody rb;
Animator anim;
bool facingRight;
float distToGround;
void Start()
{
rb = GetComponent<Rigidbody>();
anim = GetComponent<Animator>();
}
void FixedUpdate()
{
float move = Input.GetAxis("Horizontal");
// Stops player sticking to wall
if (!isGrounded() && Mathf.Abs(move) > 0.01f) return;
if (move != 0f) anim.SetBool("isRunning", true);
else if (move == 0f) anim.SetBool("isRunning", false);
if (Input.GetKey("right")) rb.velocity = new Vector3(move * runSpeed, rb.velocity.y, 0);
if (Input.GetKey("left")) rb.velocity = new Vector3(-move * -runSpeed, rb.velocity.y, 0);
if (Input.GetButton("Jump") && isGrounded())
{
anim.SetTrigger("isJumping");
rb.velocity = new Vector3(rb.velocity.x, jumpHeight, 0);
}
}
//Check if grounded
bool isGrounded() { return Physics.Raycast(transform.position, -Vector3.up, distToGround + 0.1f); }
I am using a raycast to detect if grounded. I think when my capsule collider is just on the edge of platform it counts as not grounded, therefore he cant move.