Arcade Physics Jump through platform

Hi, I have a platform that I would like the player to be able to jump through/stand on. I already got most of the functionality by changing the collisions of the sides and only enabling “top” to collide, however I’m confused on how the player can go back down again if wanted to. I would like to jump down through the platform. Is this possible with Arcade Physics??

Hi,

Don’t worry, you can almost always code a solution. For examples :

  1. You can set the position of the player a few pixels lower, he should fall through the platform
  2. You can skip collisions with platforms for a few frames, just the time for the player to fall using processCallback on the Collider. Let’s say you add a member standing on the player, with a value of true by default. On a collision, the collider checks this variable before separating bodies. On a key press, you change the value of standing to false, so collisions will be skipped. 500 ms later, you change back the value to true (here I will let you use your favorite method to manage timing).
  3. By another better way I am eager to discover
1 Like

How exactly do you do this? I’m working on trying to get this first part (allowing players to jump up through platforms) but have only got collisions happening on all sides of the tiles right now.

To clarify, I can see these Tile docs but I’m not sure where to apply that property. I tried setting collideDown to false as a tile property in Tiled but that didn’t work.

I’m guessing I can apply this property to an array of tile objects that I have in the layer I care about but I can’t find an array like this anywhere that’s relatively easy to access. I thought it would be available in the layer object but haven’t been able to find it yet.

1 Like

Off the top of my head, I think it’s something like body.checkCollision.left = false; body.checkCollision.right = false; body.checkCollision.bottom = false

This is the simple syntax:
tile.setCollision(false, false, true, false); // left, right, up, down

In case any other google searchers are wondering:

The tiles can be accessed in Tilemap.layer.data. For example:

    const level = this.map.createStaticLayer(0, tileset, 0, 0)

    const tileCollisions = [0, 1, 2, 3] // designate which tiles in the tileset you want to make collideable
    
    level.layer.data.forEach(function (row) {
      row.forEach(function (tile) {
        if (tileCollisions.includes(tile.index)) {
          tile.collideDown = false
          tile.collideLeft = false
          tile.collideRight = false
          tile.collideUp = true
          // or less verbosely:
          // tile.setCollision(false, false, true, false)
        }
      })
    })
2 Likes