Custom Collisions (Arcade Physics on Tilemap)

Hello!

I’m trying manage custom collision on a Tilemap made with Tiled.

  • Orange squares are collision with .setCollisionByProperty({ collides: true }) and works OK.
  • Yellow squares are tile with a custom collision. I’m trying stop character on cyan inner shape.

image

In this custom collision, I get collisionGroup and analyze shapes.

I need some approach to work with this. I tried:

  • Use tile.setCollisionCallback() on .forEachTile() on create() map function (works, and detect collision. My character stop, but up & down key and continue enter pixel to pixel. (Maybe my problem is “How should I stop my character” ?)
  • Use this.physics.world.collideTiles() or this.physics.world.collide() (don’t works).
  • Maybe items like as rocks (with yellow/cyan custom shape) should I put it as “static bodies” (and control with touching)?

Some tips with any recommends or better approach?

Thanks!

how do you move your character?

i did encounter similar problem previously when trying to rotate an object. that result in collision not processed properly since i use base rotation function. ended up doing fine when using angular velocity.

just making sure that you are not moving your character using position/ translate.

Thanks for answer, @as3mbus.

I move my character with .setVelocity().

Finally, I use this config:

  • I use tile.setCollisionCallback() for each tile with CollisionGroup (defined in Tiled).
  • This function always set character .body.moves to true. But, if this function detect collision, set character .body.moves to false (stop character) and manually update .body.blocked.*

With this, all works fine, but I don’t know if exists a better way.

PS: With this config, only have a problem: When I press some cursor (ex: UP) and also press other cursor (ex: RIGHT), character don’t move. I need up all cursors and press again for move.

1 Like