# How can I use the accelerometer in phaser 3?

**URL:** <https://phaser.discourse.group/t/how-can-i-use-the-accelerometer-in-phaser-3/11451>\
**Category:** Phaser 3\
**Created:** [March 25, 2022, 12:22am UTC](https://phaser.discourse.group/t/how-can-i-use-the-accelerometer-in-phaser-3/11451 "2022-03-25T00:22:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ederish\_Herrera](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/ederish_herrera/32/5534_2.png) [@Ederish\_Herrera](https://phaser.discourse.group/u/Ederish_Herrera)\
**Post date:** [March 25, 2022, 12:22am UTC](https://phaser.discourse.group/t/how-can-i-use-the-accelerometer-in-phaser-3/11451/1 "2022-03-25T00:22:11Z")

</div>

Hello, I want to make a shoot em up in which the ship moves using the phone’s gyroscope, for this I use the Gyro.js library

This is the game code

```javascript
var config = {
    type: Phaser.AUTO,
    scale:{mode: Phaser.Scale.ENVOLVED,},
    width: 800, height: 600,
    parent: 'container',
    scene: {
        preload: preload,
        create: create,
        update: update
    },
    physics:{default:"arcade"}
};
var bullets;
var ship;
var speed;
var stats;
var cursors;
var lastFired = 0;

var game = new Phaser.Game(config);

function preload (){
    this.load.image('ship', 'http://examples.phaser.io/assets/sprites/thrust_ship2.png');
    this.load.image('bullet', 'http://examples.phaser.io/assets/misc/bullet0.png');
    this.load.image('bg', 'http://examples.phaser.io/assets/skies/starfield.png')
}

function create (){
    
    this.add.image(400, 300, 'bg').setDisplaySize(800, 600);

    var Bullet = new Phaser.Class({

        Extends: Phaser.GameObjects.Image,

        initialize:

        function Bullet (scene){
            Phaser.GameObjects.Image.call(this, scene, 0, -4, 'bullet');

            this.speed = Phaser.Math.GetSpeed(300, 1);
        },

        fire: function (x, y){
            this.setPosition(x, y - 10);

            this.setActive(true);
            this.setVisible(true);
        },
        update: function (time, delta){
            this.y -= this.speed * delta;

            if (this.y < -25)
            {
                this.setActive(false);
                this.setVisible(false);
            }
        }

    });
    bullets = this.add.group({
        classType: Bullet,
        maxSize: 20,
        runChildUpdate: true
    });

    // Create the objects in advance, so they're ready and waiting in the pool
    bullets.createMultiple({ quantity: 20, active: false });

    ship = this.physics.add.sprite(400, 580, 'ship').setDepth(1)
    .setCollideWorldBounds(true);

    cursors = this.input.keyboard.createCursorKeys();

    speed = Phaser.Math.GetSpeed(300, 1);

}
function update (time, delta){ 
    
    if (cursors.left.isDown){
        ship.x -= speed * delta;
    }
    else if (cursors.right.isDown){
        ship.x += speed * delta;
    }
    if (cursors.space.isDown && time > lastFired){

        var bullet = bullets.get();
        if (bullet){

            bullet.fire(ship.x, ship.y);
            lastFired = time + 50;
}
}}

```

This is the code of gyro.js

```javascript
// setting gyroscope update frequency
gyro.frequency = 500;
// start gyroscope detection
gyro.startTracking((o)=>{g=o.gamma; document.write(g)})

```

the problem is that the value of gamma is null

![image](https://global.discourse-cdn.com/free1/uploads/phaser1/original/2X/5/53dac6d74a0c1ab938127831099dddc894ca3838.png)

How do I make gamma return the value of the gyroscope?

it is supposed to display a data of type double
