# Ferris Wheel Platform Collision Issue

**URL:** <https://phaser.discourse.group/t/ferris-wheel-platform-collision-issue/11496>\
**Category:** Phaser 3\
**Created:** [April 6, 2022, 6:31am UTC](https://phaser.discourse.group/t/ferris-wheel-platform-collision-issue/11496 "2022-04-06T06:31:09Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![t\_rev44](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/t_rev44/32/4157_2.png) [@t\_rev44](https://phaser.discourse.group/u/t_rev44)\
**Post date:** [April 6, 2022, 6:31am UTC](https://phaser.discourse.group/t/ferris-wheel-platform-collision-issue/11496/1 "2022-04-06T06:31:09Z")

</div>

[https://global.discourse-cdn.com/free1/uploads/phaser1/original/2X/d/deecb84c828c6663151d91364f234b4c93df4682.mp4](https://global.discourse-cdn.com/free1/uploads/phaser1/original/2X/d/deecb84c828c6663151d91364f234b4c93df4682.mp4)

I would like the character to stay on the platform as it revolves around the point, instead they stay in the same x coordinate and slide off. Below is my code for the ferris wheel.

I tried a workaround where I just move it around the point in an octagon, but that also has a problem. Any time the platform either stops moving upward or starts moving downward, the player doesn’t stick to it and changes to the “falling” state for 1 to 3 frames (I switch it to that state when it recognizes that player.body.onFloor() == false). Any way to make the player stay planted on the platform while it starts to descend?

Thanks in advance.

```javascript
export default class FerrisWheel {

constructor(scene, player){
    scene.ferris_wheels = scene.physics.add.group();
    this.scene = scene
    this.player = player
    this.scene.ferris_wheel_array = []

    this.once = false

}

update(player){
  this.scene.ferris_wheel_array.forEach(function(ferris_wheel) {

    for (var i=0; i<ferris_wheel.data.values.obj.ferris_wheel_cabins.length; i++){
      Phaser.Actions.RotateAroundDistance([ferris_wheel.data.values.obj.ferris_wheel_cabins[i]], { x: ferris_wheel.x, y: ferris_wheel.y }, 0.0147, 200);
    }

  }) 
}

addFerrisWheel(scene, x, y, scale, angular_velocity) {

    var ferris_wheel = scene.ferris_wheels.create(x, y, 'ferris_wheel_base');
    ferris_wheel.setActive(true).setVisible(true);
    ferris_wheel.setScale(scale);
    ferris_wheel.setDepth(800);
    scene.ferris_wheel_array.push(ferris_wheel)

    ferris_wheel.setData({
                  'layer_collisions': [],
                  'can_spawn': true,
                  'obj': this,
					       });

		scene.ferris_wheels.add(ferris_wheel);
    ferris_wheel.body.immovable = true;
    ferris_wheel.body.setAllowGravity(false)
    ferris_wheel.setAngularVelocity(angular_velocity)

    ferris_wheel.stand = scene.physics.add.sprite(x, y + 150, 'ferris_wheel_stand')
    ferris_wheel.stand.body.setAllowGravity(false);
    ferris_wheel.stand.setScale(scale).setDepth(700)

    this.ferris_wheel_cabins = []

    ferris_wheel.cabin1 = scene.physics.add.sprite(x, y + 175, 'ferris_wheel_cabin')
    console.log(ferris_wheel.cabin1);

    ferris_wheel.cabin1.setActive()
    ferris_wheel.cabin1.body.setAllowGravity(false);
    ferris_wheel.cabin1.setScale(scale).setDepth(850).setFrame(0)
    ferris_wheel.cabin1.body.immovable = true
    this.ferris_wheel_cabins.push(ferris_wheel.cabin1)

    for (var i=0; i<this.ferris_wheel_cabins.length; i++){
      scene.physics.add.collider(this.ferris_wheel_cabins[i], this.player.player,
        function(platform, player){
          platform.body.immovable = true
          player.body.immovable = false
        },
        function(platform, player){
          var v = (player.obj.scene.game.data.health > 0)
          return v
        }
      )
    }

    return ferris_wheel

}

}

```

---

<div class="post-metadata">

**Author:** ![Puccini](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/puccini/32/4984_2.png) [@Puccini](https://phaser.discourse.group/u/Puccini)\
**Post date:** [April 6, 2022, 2:04pm UTC](https://phaser.discourse.group/t/ferris-wheel-platform-collision-issue/11496/2 "2022-04-06T14:04:39Z")

</div>

If i remember correct, u need to Set friction…

But there may also be another Problem with moving plattforms 🙂  
See here:

> [@Riding plattform disables collision with walls / other objects](https://phaser.discourse.group/t/riding-plattform-disables-collision-with-walls-other-objects/10254):
>
> Hi there, i’ve found this post here: [Bug regression riding a moving body ignore collision](https://phaser.discourse.group/t/bug-regression-riding-a-moving-body-ignore-collisions/6827) I thought this was fixed, but in my actually game i can “ride” into a wall if i stand on a moving plattform. This is my plattform group setup: this.plattforms = this.physics.add.group({ immovable: true, allowGravity: false, frictionX: 1, }); this.physics.add.collider( this.hero, this.plattforms ); And this is where i move each pla…

---

<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 6, 2022, 6:18pm UTC](https://phaser.discourse.group/t/ferris-wheel-platform-collision-issue/11496/3 "2022-04-06T18:18:55Z")

</div>

Friction movement requires a body delta, usually by velocity. If you calculate the distance moved by `RotateAroundDistance()` you can maybe give the cabins a fake velocity (with `body.moves = false`). You will have to convert by the `delta` in `update()`.

---

<div class="post-metadata">

**Author:** ![t\_rev44](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/t_rev44/32/4157_2.png) [@t\_rev44](https://phaser.discourse.group/u/t_rev44)\
**Post date:** [April 7, 2022, 12:56am UTC](https://phaser.discourse.group/t/ferris-wheel-platform-collision-issue/11496/4 "2022-04-07T00:56:29Z")

</div>

I can settle for the octagon pattern like this, but as you can see, the fact that she switches to jump state for a few frames is a problem. This happens when the cabin moves from up/right to right, and again when it moves from right to down/right.

[https://global.discourse-cdn.com/free1/uploads/phaser1/original/2X/a/a645f2ff82ee9ff701ae583e21b45ffdd0c291de.mp4](https://global.discourse-cdn.com/free1/uploads/phaser1/original/2X/a/a645f2ff82ee9ff701ae583e21b45ffdd0c291de.mp4)

I tried adding friction and high gravity. What else is needed to get her to stay in the idle state when it starts to descend?

Here’s the collision

```javascript
    for (var i=0; i<this.ferris_wheel_cabins.length; i++){
      scene.physics.add.collider(this.ferris_wheel_cabins[i], this.player.player,
        function(platform, player){
          platform.body.immovable = true
          player.body.immovable = false
          player.setGravityY(100000)
          platform.body.setFriction(1, 1)},
        function(platform, player){
          var v = (player.obj.scene.game.data.health > 0)})}

```

---

<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 7, 2022, 1:13am UTC](https://phaser.discourse.group/t/ferris-wheel-platform-collision-issue/11496/5 "2022-04-07T01:13:44Z")

</div>

Friction won’t work unless the cabins have velocity. And there’s no need to set `friction` or `immovable` within the collision callback.

You may have to move the cabin revolutions into the `WORLD_STEP` event, and move the bodies instead.

---

<div class="post-metadata">

**Author:** ![t\_rev44](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/t_rev44/32/4157_2.png) [@t\_rev44](https://phaser.discourse.group/u/t_rev44)\
**Post date:** [April 7, 2022, 3:52am UTC](https://phaser.discourse.group/t/ferris-wheel-platform-collision-issue/11496/6 "2022-04-07T03:52:46Z")

</div>

They do have velocity, I’m using a primitive method of moving them using compass direction states (code below). I’m not sure what you mean by the WORLD\_STEP event, does that just mean move them inside update()?

Btw, I set the friction to 1, 1 on one of the cabins but not the other, yet the player behaves the same way when standing on each of them.

```javascript
export default class FerrisWheel {

constructor(scene, player){
    scene.ferris_wheels = scene.physics.add.group();
    this.scene = scene
    this.player = player
    this.scene.ferris_wheel_array = []

    this.once = false

}

update(player){
  this.scene.ferris_wheel_array.forEach(function(ferris_wheel) {

    for (var i=0; i<ferris_wheel.data.values.obj.ferris_wheel_cabins.length; i++){
      // Phaser.Actions.RotateAroundDistance([ferris_wheel.data.values.obj.ferris_wheel_cabins[i]], { x: ferris_wheel.x, y: ferris_wheel.y }, 0.0147, 200);
      var cabin = ferris_wheel.data.values.obj.ferris_wheel_cabins[i]
      var s = 100
      var d = 75

      if (cabin.state == 'w'){
        cabin.setVelocity(-s, 0)
        if (cabin.x < 600){
          cabin.state = 'nw'}}

      if (cabin.state == 'nw'){
        cabin.setVelocity(-d, -d)
        if (cabin.y < 600 || cabin.x < 500){
          cabin.state = 'n'}}

      if (cabin.state == 'n'){
        cabin.setVelocity(0, -s)
        if (cabin.y < 400){
          cabin.state = 'ne'}}

      if (cabin.state == 'ne'){
        cabin.setVelocity(d, -d)
        if (cabin.x > 600 || cabin.y < 300){
          cabin.state = 'e'}}

      if (cabin.state == 'e'){
        cabin.setVelocity(s, 0)
        if (cabin.x > 800){
          cabin.state = 'se'}}

      if (cabin.state == 'se'){
        cabin.setVelocity(d, d)
        if (cabin.y > 400 || cabin.x > 900){
          cabin.state = 's'}}

      if (cabin.state == 's'){
        cabin.setVelocity(0, s)
        if (cabin.y > 600){
          cabin.state = 'sw'}}

      if (cabin.state == 'sw'){
        cabin.setVelocity(-d, d)
        if (cabin.x < 800 || cabin.y > 700){
          cabin.state = 'w'}}

    }

  })
}

addFerrisWheel(scene, x, y, scale, angular_velocity) {

	var ferris_wheel = scene.ferris_wheels.create(x, y, 'ferris_wheel_base');
	ferris_wheel.setActive(true).setVisible(true);
    ferris_wheel.setScale(scale);
	ferris_wheel.setDepth(800);
    scene.ferris_wheel_array.push(ferris_wheel)

    ferris_wheel.setData({
                  'layer_collisions': [],
                  'can_spawn': true,
                  'obj': this,
			});

	scene.ferris_wheels.add(ferris_wheel);
    ferris_wheel.body.immovable = true;
    ferris_wheel.body.setAllowGravity(false)
    ferris_wheel.setAngularVelocity(angular_velocity)

    ferris_wheel.stand = scene.physics.add.sprite(x, y + 150, 'ferris_wheel_stand')
    ferris_wheel.stand.body.setAllowGravity(false);
    ferris_wheel.stand.setScale(scale).setDepth(700)

    this.ferris_wheel_cabins = []

    ferris_wheel.cabin1 = scene.physics.add.sprite(x, y + 175, 'ferris_wheel_cabin')
    ferris_wheel.cabin1.setActive()
    ferris_wheel.cabin1.body.setAllowGravity(false);
    ferris_wheel.cabin1.setScale(scale).setDepth(850).setFrame(0)
    ferris_wheel.cabin1.body.immovable = true
    ferris_wheel.cabin1.setSize(42, 18)
    ferris_wheel.cabin1.setOffset(1,1)
    this.ferris_wheel_cabins.push(ferris_wheel.cabin1)
    ferris_wheel.cabin1.state = 'w'

    ferris_wheel.cabin2 = scene.physics.add.sprite(x, y - 175, 'ferris_wheel_cabin')
    ferris_wheel.cabin2.setActive()
    ferris_wheel.cabin2.body.setAllowGravity(false);
    ferris_wheel.cabin2.setScale(scale).setDepth(850).setFrame(1)
    ferris_wheel.cabin2.body.immovable = true
    ferris_wheel.cabin2.setSize(42, 18)
    ferris_wheel.cabin2.setOffset(1,1)
    ferris_wheel.cabin2.body.setFriction(1, 1)
    this.ferris_wheel_cabins.push(ferris_wheel.cabin2)
    ferris_wheel.cabin2.state = 'e'

    for (var i=0; i<this.ferris_wheel_cabins.length; i++){
      scene.physics.add.collider(this.ferris_wheel_cabins[i], this.player.player,
        function(platform, player){
          // platform.body.immovable = true
          // player.body.immovable = false
          // player.setGravityY(100000)
        },
        function(platform, player){
          var v = (player.obj.scene.game.data.health > 0)})}

    return ferris_wheel

}

}

```

---

<div class="post-metadata">

**Author:** ![t\_rev44](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/t_rev44/32/4157_2.png) [@t\_rev44](https://phaser.discourse.group/u/t_rev44)\
**Post date:** [April 7, 2022, 4:52am UTC](https://phaser.discourse.group/t/ferris-wheel-platform-collision-issue/11496/7 "2022-04-07T04:52:39Z")

</div>

I set the player’s y velocity to 150 in the collision callback and now it works fine. Can you think of any unwanted side effect of this or is it ok for me to go with it?

---

<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 7, 2022, 5:09am UTC](https://phaser.discourse.group/t/ferris-wheel-platform-collision-issue/11496/8 "2022-04-07T05:09:29Z")

</div>

The default body friction (1, 0) already allows for horizontal platform movement.

The y velocity sounds fine.
