# Physics Moving Platform / Match velocity does not work well

**URL:** <https://phaser.discourse.group/t/physics-moving-platform-match-velocity-does-not-work-well/7509>\
**Category:** Phaser 3\
**Created:** [September 26, 2020, 7:53pm UTC](https://phaser.discourse.group/t/physics-moving-platform-match-velocity-does-not-work-well/7509 "2020-09-26T19:53:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![whoshotdk](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/whoshotdk/32/4009_2.png) [@whoshotdk](https://phaser.discourse.group/u/whoshotdk)\
**Post date:** [September 26, 2020, 7:53pm UTC](https://phaser.discourse.group/t/physics-moving-platform-match-velocity-does-not-work-well/7509/1 "2020-09-26T19:53:11Z")

</div>

Hi there,

First-time poster, first-time Phaser user here.

I have a ‘boat’, which is a physics enabled (Arcade) container that contains a “platform” physics-enabled rectangle. Both container and the platform within it have Y gravity at 0 and are immovable (so that the player does not push them).

The boat just sits in the middle of the screen until the player wishes to move it by modifying a ‘power’ variable (done via a button press) - it moves towards the right; like so;

Boat.Update() {

```
this.body.acceleration.x += this.power;

// "Friction".
this.body.velocity.x *= .7;

// No reversing please!
if(this.body.velocity.x < 0)
	this.body.velocity.x = 0;
}

```

}

I also have a ‘player’, physics enabled. Platformer style movement pretty much ripped straight from the Phaser3 platform tutorial.

When the player collides with the boat, a flag is set (player ‘Z’ is set to zero when colliding with the boat).

Everything works well, until I start adding acceleration to the boat. No matter what I do, the player tends to slide along the boat’s surface (as the boat moves beneath them).

I’ve tried setting body friction to 1 on both the boat and the player. No effect.

I’ve tried " player.body.velocity.x = boat.body.velocity.x " in an Update method. This almost works; it reduces the slide but nevertheless the slide is still there.  
I’ve tried doing that same thing in “Pre/Post” Update methods (after having registered them). No change.

The player movement is handled by the following method, called in Scene Update when appropriate key is pressed.

Player.Move(\_dir) {

```
if(_dir == -1)
	this.body.velocity.x = -160;
else if(_dir == 1)
	this.body.velocity.x = 160;
else
	this.body.velocity.x = this.z == 0 ? this.boat.body.velocity.x : 0;

```

}

You can see that I’m attempting to set the velocity depending on the flag in that method too. Doesn’t seem to make a difference whether I do that ternary check or just set 0 whenever \_dir == 0.

I’ve even tried setting the player’s gravity really high when they’re colliding with the platform;

Player.CollisionVsPlatform(\_player, \_platform) {

```
if(_platform.body.moves && _platform.body.touching.up && _player.body.touching.down)
	_player.body.gravity.y = 10000;

```

}

The method is called but does not appear to do anything.

I’ve uploaded the entire thing here: [http://www.whoshotdk.co.uk/phaser/](http://www.whoshotdk.co.uk/phaser/)

The ‘boat’, ‘player’ and other scripts are here: [http://www.whoshotdk.co.uk/phaser/Asset/GameScene/](http://www.whoshotdk.co.uk/phaser/Asset/GameScene/)

The main scene file resides there too, it’s called GameScene.scene.

The game: [http://www.whoshotdk.co.uk/phaser/game.html](http://www.whoshotdk.co.uk/phaser/game.html)

In order to make the boat move, jump the player up onto it (up arrow), walk into the red box, then left-click the ‘+’ button that appears. You’ll see the boat move and the player slide. Note; if you cant jump high enough, make the window smaller and refresh. I haven’t got round to handling different screen sizes yet!

I’d appreciate any advice on this!

Thanks  
Dave

---

<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:** [September 26, 2020, 8:18pm UTC](https://phaser.discourse.group/t/physics-moving-platform-match-velocity-does-not-work-well/7509/2 "2020-09-26T20:18:43Z")

</div>

👋

I can’t reach the boat. ☹

All I can think of is try to do it without containers.

---

<div class="post-metadata">

**Author:** ![whoshotdk](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/whoshotdk/32/4009_2.png) [@whoshotdk](https://phaser.discourse.group/u/whoshotdk)\
**Post date:** [September 26, 2020, 8:21pm UTC](https://phaser.discourse.group/t/physics-moving-platform-match-velocity-does-not-work-well/7509/3 "2020-09-26T20:21:02Z")

</div>

Thanks Samme,

Yes as this is my literal first day with Phaser, I have yet to work out how to handle screen scaling as regards to forces and positions in the game 🙂

If you make the window less tall, you’ll find you can reach it.

No containers eh? I’m only using it so I can organise my entities into some sort of logical ecapsulation - I’d rather not stuff everything into the scene.

Nevertheless I suppose I can give that a go. Thanks!

Edit; I would appreciate an explanation of why not using a container would help, if you have the inclination to do so and the time.

---

<div class="post-metadata">

**Author:** ![Milton](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@Milton](https://phaser.discourse.group/u/Milton)\
**Post date:** [September 26, 2020, 9:54pm UTC](https://phaser.discourse.group/t/physics-moving-platform-match-velocity-does-not-work-well/7509/4 "2020-09-26T21:54:57Z")

</div>

Perhaps [this](https://phaser.discourse.group/t/riding-moving-platforms/7330) topic can help?

---

<div class="post-metadata">

**Author:** ![whoshotdk](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/whoshotdk/32/4009_2.png) [@whoshotdk](https://phaser.discourse.group/u/whoshotdk)\
**Post date:** [September 26, 2020, 10:06pm UTC](https://phaser.discourse.group/t/physics-moving-platform-match-velocity-does-not-work-well/7509/5 "2020-09-26T22:06:09Z")

</div>

Thanks @Milton!

Unfortuantely for me, I have already seen that article - I’m not actually using tweens but having said that I have tried code that is very similar.

It turns out there is an issue with my use of a container - I’ve just finished a very quick demo with just a couple of sprites - I didn’t need to do anything to make the player follow the moving platform; the Arcade physics just worked. I think I read somewhere that’s expected 😃

I’m probably going to remove the container and programatically ‘parent’ my boat entities ( collider rectangle, boat sprite and red box) together instead.

As I’m new I can’t even blame the behaviour on a bug (no one would believe me, including me, hah) but I do intend to test this container behaviour some more soon.

Thanks again!
