# How to use setVelocity in a class extending Phaser.Physics.Arcade.Sprite?

**URL:** <https://phaser.discourse.group/t/how-to-use-setvelocity-in-a-class-extending-phaser-physics-arcade-sprite/8847>\
**Category:** Phaser 3\
**Created:** [February 8, 2021, 9:37am UTC](https://phaser.discourse.group/t/how-to-use-setvelocity-in-a-class-extending-phaser-physics-arcade-sprite/8847 "2021-02-08T09:37:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chriswgr](https://avatars.discourse-cdn.com/v4/letter/c/7bcc69/32.png) [@Chriswgr](https://phaser.discourse.group/u/Chriswgr)\
**Post date:** [February 8, 2021, 9:37am UTC](https://phaser.discourse.group/t/how-to-use-setvelocity-in-a-class-extending-phaser-physics-arcade-sprite/8847/1 "2021-02-08T09:37:58Z")

</div>

Hello, I want to create a Player class in for my RPG which has all the properties and methods of sprites but also will eventually have things like an inventory, health, stats, etc.

```
class Player extends Phaser.Physics.Arcade.Sprite {
    constructor(...args) {
        super(...args);
        this.inventory = [];
    }
    pickup(item) {
        if (this.inventory.length < 5) {
            this.invertory.push(item);
        }
    }
}

```

However, from what I can tell, I cannot use any of the set methods for Phaser.Physics.Arcade.Sprite objects. For example, when I try to move my player

```
let player = new Player(this, 800, 800, 'player');
player.setVelocityX(100);

```

I get this error (in chrome console)

> Uncaught TypeError: Cannot read property ‘setVelocityX’ of null  
> at Player.setVelocityX (phaser.min.js:1)  
> at playGame.create (game.js:33)

I’m pretty new to javascript and phaser but I want to code following good practices. I wonder if my idea to make Player extend Sprite is not a good way to achieve the functionality I want, so would like to hear if you think there is a better approach too.

---

<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:** [February 8, 2021, 3:15pm UTC](https://phaser.discourse.group/t/how-to-use-setvelocity-in-a-class-extending-phaser-physics-arcade-sprite/8847/2 "2021-02-08T15:15:05Z")

</div>

👋

The Arcade game object classes do not themselves create a physics body, so calling `super()` in an extended class will not create one either.

- [How do I extend a game object?](https://github.com/samme/phaser3-faq/wiki#how-do-i-extend-a-game-object)
- [extending Arcade Sprite](http://labs.phaser.io/view.html?src=src/physics/arcade/extending%20arcade%20sprite.js)
