Unity2D Rigidbody2D.Velocity clipping through walls.

Input Script:

    private void FixedUpdate()
    {
        //Speed
        InputX = Input.GetAxisRaw("Horizontal");
        InputY = Input.GetAxisRaw("Vertical");

        Movement = new Vector2(InputX, InputY);

        if (InputX != 0 || InputY != 0)
        {
            Player_Manager_S.Player_Movement_S.Walking();
        }

Movement Script:

    public void Walking()
    {
        rb.velocity = Movement * Speed * Time.deltaTime;
    }

And result in the video:

(If you have any ideas why it’s happening I would be more than happy to know

First, this line makes no sense. You do not need to set an absolute velocity by scaling it by the current elapsed time. Velocity will be time-integrated to position later.

You don’t show how it’s rotating which is likely you’re changing the Transform or just instantly changing it causing overlaps. Because the physics system cannot use velocity adequately to keep them separated, because you’re stomping over it, it gets into an impossible situation.

Changing it to use Continuous Collision Detection might help but it won’t stop the overlaps you’re causing.

Ohhhhhh right!!! The rotation, I completely forgot about that, I’ve checked and you were right, I fixed the code and it’s almost perfect now, Thanks for answering & the tips as well, Really appreciate that.
Have a good day :slight_smile:

1 Like

Good luck.