# Prevent objects from passing through walls / tunneling

**URL:** <https://phaser.discourse.group/t/prevent-objects-from-passing-through-walls-tunneling/1883>\
**Category:** Phaser 3\
**Created:** [March 28, 2019, 6:36pm UTC](https://phaser.discourse.group/t/prevent-objects-from-passing-through-walls-tunneling/1883 "2019-03-28T18:36:25Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![yannick](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/yannick/32/732_2.png) [@yannick](https://phaser.discourse.group/u/yannick)\
**Post date:** [April 1, 2019, 5:34am UTC](https://phaser.discourse.group/t/prevent-objects-from-passing-through-walls-tunneling/1883/6 "2019-04-01T05:34:40Z")

</div>

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.

```javascript
/**
 * 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 })

```

---

_[View the full topic](https://phaser.discourse.group/t/prevent-objects-from-passing-through-walls-tunneling/1883)._
