# Pausing and Unpausing Physics in Phaser 3

**URL:** <https://phaser.discourse.group/t/pausing-and-unpausing-physics-in-phaser-3/4679>\
**Category:** Phaser 3\
**Created:** [December 21, 2019, 9:12pm UTC](https://phaser.discourse.group/t/pausing-and-unpausing-physics-in-phaser-3/4679 "2019-12-21T21:12:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![HackerMan](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/hackerman/32/2683_2.png) [@HackerMan](https://phaser.discourse.group/u/HackerMan)\
**Post date:** [December 21, 2019, 9:12pm UTC](https://phaser.discourse.group/t/pausing-and-unpausing-physics-in-phaser-3/4679/1 "2019-12-21T21:12:37Z")

</div>

I am creating a Phaser 3 game and I want to pause my game when the player presses the P key. I am currently unsure of what to do to unpause the game after the player presses the P key again. Also, I want some the text appear when they pause the game, and dissapear when they upause it. Here is my code:  
`  
this.key\_W = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.W);

```
this.key_A = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.A);

this.key_D = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.D);

    this.cursorL = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.LEFT);

    this.cursorR = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.RIGHT);

    this.cursorU = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.UP);

    this.key_S = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.S);

    this.key_P = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.P);

```

`  
That was all part of the create function  
Now, for the update function:

`function update(){

```
if(this.key_W.isDown && this.player.body.touching.down){ 

            this.jump.play(); //play the jumping sound effect

	        this.player.setVelocityY(-490); //sets the jump height

}

//problem area

if(this.key_P.isDown){

      this.physics.pause();

      if(this.key_P.isDown){

               //Unpause physics here

}

```

}

}

`

---

<div class="post-metadata">

**Author:** ![Thundros](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/thundros/32/2057_2.png) [@Thundros](https://phaser.discourse.group/u/Thundros)\
**Post date:** [December 21, 2019, 9:54pm UTC](https://phaser.discourse.group/t/pausing-and-unpausing-physics-in-phaser-3/4679/2 "2019-12-21T21:54:22Z")

</div>

Hi, @HackerMan ! 🙂 I know it’s not much, but I hope this helps. I have added a variable you can use to flip whether or not Physics is paused.

Here’s the code, I hope it works, please do let me know & correct me if I’m wrong!

```javascript
this.cursorL = this.input.keyboard.addKey ( Phaser.Input.Keyboard.KeyCodes.LEFT );
this.cursorR = this.input.keyboard.addKey ( Phaser.Input.Keyboard.KeyCodes.RIGHT );
this.cursorU = this.input.keyboard.addKey ( Phaser.Input.Keyboard.KeyCodes.UP );

this.key_A = this.input.keyboard.addKey ( Phaser.Input.Keyboard.KeyCodes.A );
this.key_D = this.input.keyboard.addKey ( Phaser.Input.Keyboard.KeyCodes.D );
this.key_P = this.input.keyboard.addKey ( Phaser.Input.Keyboard.KeyCodes.P );
this.key_S = this.input.keyboard.addKey ( Phaser.Input.Keyboard.KeyCodes.S );

this.pausePhysics = false;

function update ( ) {

	if ( this.key_W.isDown && this.player.body.touching.down ) {

		// Play `Jumping` sound
		this.jump.play ( );

		// Set the `Jump` `Height`
		this.player.setVelocityY ( -490 );

	}

	// If pressing the `P` key & `physics` is `NOT` active

	if ( this.key_P.isDown && this.pausePhysics === false ) {

		// Physics becomes active
		this.pausePhysics = true;

		// Pause `Physics`
		this.physics.pause ( );

	}

	// Otherwise, if pressing the `P` key
	// & `Physics` `IS` active

	else {

		// Set `Physics` variable back to `off`
		this.pausePhysics = false;

	}

}

```

Once again, hope this helps & Merry Christmas! 🙂

---

<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:** [December 21, 2019, 10:38pm UTC](https://phaser.discourse.group/t/pausing-and-unpausing-physics-in-phaser-3/4679/3 "2019-12-21T22:38:10Z")

</div>

```
this.physics.resume()

```

will reverse the pause, if that’s what you want.

---

<div class="post-metadata">

**Author:** ![HackerMan](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/hackerman/32/2683_2.png) [@HackerMan](https://phaser.discourse.group/u/HackerMan)\
**Post date:** [December 22, 2019, 8:24pm UTC](https://phaser.discourse.group/t/pausing-and-unpausing-physics-in-phaser-3/4679/4 "2019-12-22T20:24:06Z")

</div>

Thank you! 🙂

---

<div class="post-metadata">

**Author:** ![HackerMan](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/hackerman/32/2683_2.png) [@HackerMan](https://phaser.discourse.group/u/HackerMan)\
**Post date:** [December 22, 2019, 8:24pm UTC](https://phaser.discourse.group/t/pausing-and-unpausing-physics-in-phaser-3/4679/5 "2019-12-22T20:24:42Z")

</div>

Thank you 🙂
