Prevent objects from passing through walls / tunneling

I do not know what type of game you are making, but in a platformer I made with matter, I use applyForce instead of setVelocity, which helped a lot. See the snippet below.

/**
 * We use setVelocity to jump
 * and applyForce to move right and left
 */

// Jump
if (y !== 0) this.Matter.Body.setVelocity(this.body, { x: this.body.velocity.x, y })

// Move
this.Matter.Body.applyForce(this.body, { x: 0, y: 0 }, { x, y: 0 })

// check max velocity
let maxVelocityX =
  this.body.velocity.x > this.maxVelocity.x ? 1 : this.body.velocity.x < -this.maxVelocity.x ? -1 : null
if (maxVelocityX)
  this.Matter.Body.setVelocity(this.body, { x: this.maxVelocity.x * maxVelocityX, y: this.body.velocity.y })