Skip to content
Advertisement

How do you prevent player from jumping up walls using the matter physics engine with a tilemap in Phaser 3

Im trying to create a platformer game in phaser 3 using the matter physics engine, currently im trying to create levels using tiled, I have gotten to a point where the player can’t infinitely jump however they can still jump up walls.

Im currently trying to make it so they can only jump if they are colliding with a specific layer called floor.

When I try to use the code below I get an error saying:

Uncaught TypeError: Cannot set properties of null (setting ‘label’)

game.js (create function):

JavaScript

Sorry if this is a really easy fix or just doesn’t work and I’m being stupid.

Advertisement

Answer

I’m no matter.js-engine expert, but I assume the error happens on the line this.floor.body.label = 'floor'. A easy solution would be to use the options parameter, from the convertTilemapLayer method (Documentation).

Here a working Demo:
(code based on this phaser.io example )

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement