Ferris Wheel Platform Collision Issue

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.

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

}

}

If i remember correct, u need to Set friction…

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

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().

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.

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

    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)})}

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.

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.

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

}

}

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?

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

The y velocity sounds fine.