# Move to position - Arcade Physics

**URL:** <https://phaser.discourse.group/t/move-to-position-arcade-physics/5941>\
**Category:** Phaser 3\
**Created:** [April 17, 2020, 3:02pm UTC](https://phaser.discourse.group/t/move-to-position-arcade-physics/5941 "2020-04-17T15:02:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Phailser](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/phailser/32/3187_2.png) [@Phailser](https://phaser.discourse.group/u/Phailser)\
**Post date:** [April 17, 2020, 3:02pm UTC](https://phaser.discourse.group/t/move-to-position-arcade-physics/5941/1 "2020-04-17T15:02:57Z")

</div>

I am trying to have a sprite jump platform to platform in a left to right motion (see the image below)

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

I am not sure about the best way to go about this but I have implemented arcade physics. Ideally I want the sprite to jump to the next platform to an exact position or an exact distance so just pushing with an amount of velocity doesn’t seem correct. I have included a stack blitz coded example of doing so - all the source code is there too - any help would be greatly appreciated. Thanks

> **[phaser-3-jump-test-g3jd2k - StackBlitz](https://stackblitz.com/edit/phaser-3-jump-test-g3jd2k)**
>
> Blank starter project for building ES6 apps.

Adding code here for historical purposes:

```
var config = {
  type: Phaser.AUTO,
  scale: {
width: 300,
height: 480
  },
  scene: {
preload: preload,
create: create,
update: update
  },
  physics: {
default: 'arcade',
arcade: {
  debug: false
},
  },
  backgroundColor: "#6E615E"
};
const game = new Phaser.Game(config);
let box;
function preload() {}
function create() {
box = this.add.rectangle(80, 420, 20, 20, 0xffffff); 
const groundLeft = this.add.rectangle(0, 480-20, 100, 20, 0x6666ff).setOrigin(0,0);
const groundRight = this.add.rectangle(200, 480-20*4, 100, 20, 0x6666ff).setOrigin(0,0);

this.physics.add.existing(box);
this.physics.add.existing(groundLeft);
this.physics.add.existing(groundRight);
box.body.gravity.y = (100);
groundLeft.body.immovable = true;
groundRight.body.immovable = true;
this.physics.add.collider(groundLeft, box);
this.physics.add.collider(groundRight, box);

this.input.on('pointerdown', ()=>{
  box.body.setVelocityY(-110);
  box.body.setVelocityX(100);
});
} 
function update() {
  if(box.x > 300 || box.y > 480) {
this.scene.restart();
  }
}
```

---

<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:** [April 17, 2020, 3:34pm UTC](https://phaser.discourse.group/t/move-to-position-arcade-physics/5941/2 "2020-04-17T15:34:26Z")

</div>

I think you can still do it with velocity as long as you stop the box at the end of the jump. You could do that in a collision callback or in `update()`. Here it is in `update()`:

[https://stackblitz.com/edit/phaser-3-jump-test-g3jd2k?embed=1&file=index.js](https://stackblitz.com/edit/phaser-3-jump-test-g3jd2k?embed=1&file=index.js)

---

<div class="post-metadata">

**Author:** ![Phailser](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/phailser/32/3187_2.png) [@Phailser](https://phaser.discourse.group/u/Phailser)\
**Post date:** [April 17, 2020, 4:19pm UTC](https://phaser.discourse.group/t/move-to-position-arcade-physics/5941/3 "2020-04-17T16:19:37Z")

</div>

Thanks a lot for the reply. Not sure if that link saved when you made the changes. It seems to take me to the same as what I posted.

---

<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:** [April 17, 2020, 6:14pm UTC](https://phaser.discourse.group/t/move-to-position-arcade-physics/5941/4 "2020-04-17T18:14:13Z")

</div>

I was afraid of that 😃

Depending on exactly what you want, you could do

```javascript
function update() {
  if (box.body.touching.down) {
    box.body.stop();
  }
  // …
}

```

or

```javascript
function create() {
  // …
  this.physics.add.collider(groundLeft, box, collideGroundVsBox);
  this.physics.add.collider(groundRight, box, collideGroundVsBox);
  // …
}

function collideGroundVsBox(ground, boxOnGround) {
  boxOnGround.body.stop();
}

```

---

<div class="post-metadata">

**Author:** ![Phailser](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/phailser/32/3187_2.png) [@Phailser](https://phaser.discourse.group/u/Phailser)\
**Post date:** [April 18, 2020, 12:52am UTC](https://phaser.discourse.group/t/move-to-position-arcade-physics/5941/5 "2020-04-18T00:52:41Z")

</div>

Nice this is looking good - thanks @samme!

Solution outcome:

 ![upload](https://global.discourse-cdn.com/free1/uploads/phaser1/original/2X/f/f040acad9840b720ad1f7efab0e9d71bbd0da8a9.gif)
