# Trouble adding matter physics to a Sprite GameObject

**URL:** <https://phaser.discourse.group/t/trouble-adding-matter-physics-to-a-sprite-gameobject/12061>\
**Category:** Phaser 3\
**Created:** [July 24, 2022, 6:27pm UTC](https://phaser.discourse.group/t/trouble-adding-matter-physics-to-a-sprite-gameobject/12061 "2022-07-24T18:27:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cyolveren](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/cyolveren/32/6783_2.png) [@cyolveren](https://phaser.discourse.group/u/cyolveren)\
**Post date:** [July 24, 2022, 6:27pm UTC](https://phaser.discourse.group/t/trouble-adding-matter-physics-to-a-sprite-gameobject/12061/1 "2022-07-24T18:27:29Z")

</div>

I am trying to add matter physics to a Sprite GameObject using

```javascript
const testSprite = this.add.sprite(516, 114, "test", 3);
this.testSprite = testSprite
this.matter.add.gameObject(this.testSprite);

```

but it doesn’t have any physics properties after adding matter physics to it. When I try to use `setVelocityX` method in sprite’s body, it isn’t working.

`this.testSprite.body.setVelocityX(-160);` is giving me the following error:

```javascript
TS2339: Property 'setVelocityX' does not exist on type 'Body | StaticBody | BodyType'.
  Property 'setVelocityX' does not exist on type 'StaticBody'

```

However, I can see the sprite’s body in the matter objects when I do `this.matter.getMatterBodies();` . It just can’t seem to use or find the physics properties from `this.testSprite.body`. Any help is appreciated.

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [July 24, 2022, 6:38pm UTC](https://phaser.discourse.group/t/trouble-adding-matter-physics-to-a-sprite-gameobject/12061/2 "2022-07-24T18:38:19Z")

</div>

I think there is a `this.testSprite.body` but no `setVelocityX()` method there. (There is such a method in Arcade Physics.)

You probably want to use instead:

```javascript
const testSprite = this.matter.add.sprite(516, 114, "test", 3);

this.testSprite.setVelocityX(-160);

```

---

<div class="post-metadata">

**Author:** ![cyolveren](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/cyolveren/32/6783_2.png) [@cyolveren](https://phaser.discourse.group/u/cyolveren)\
**Post date:** [July 24, 2022, 6:49pm UTC](https://phaser.discourse.group/t/trouble-adding-matter-physics-to-a-sprite-gameobject/12061/3 "2022-07-24T18:49:40Z")

</div>

Thx. I was using the Phaser Editor app which doesn’t support creating physics objects that’s why I wanted just to add matter physics using `this.matter.add.gameObject`. Doesn’t `setVelocityX` also exist in Matter Physics? At least that’s what I see on API doc [setVelocity - Phaser 3 API Documentation (beta)](https://newdocs.phaser.io/docs/3.55.2/focus/Phaser.Physics.Matter.Sprite-setVelocity)

If not, I can do it manually as you suggested, just wanted to make this work for convenience and to make use of the editor.

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [July 24, 2022, 8:18pm UTC](https://phaser.discourse.group/t/trouble-adding-matter-physics-to-a-sprite-gameobject/12061/4 "2022-07-24T20:18:59Z")

</div>

There’s no `setVelocityX()` method on a Matter Physics body, only on Matter.Image and Matter.Sprite. And `matter.add.gameObject()` adds a physics body but not any methods.
