'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):
create() {
//External function to create player
player(this,'test',300,200,'player')
pawn.setScale(1.5)
pawn.setDepth(2)
pawn.setBounce(0.1)
pawn.setFriction(0,0,1)
pawn.setCircle(20)
pawn.setMass(1)
this.touchingGround = false;
this.jumpForce = 0.05
this.map = this.make.tilemap({key: 'lv3'})
this.tileset = this.map.addTilesetImage('tiles','tile', 32, 32)
this.walls = this.map.createLayer('walls', this.tileset)
this.walls.setCollisionByExclusion(-1, true);
this.floor = this.map.createLayer('floor', this.tileset)
this.floor.setCollisionByExclusion(-1, true);
this.matter.world.convertTilemapLayer(this.walls);
this.matter.world.convertTilemapLayer(this.floor);
pawn.body.label = 'player'
this.floor.body.label = 'floor'
this.matter.world.on("collisionactive", (e,o1, o2) => {
if(o1.label == 'player' && o2.label == 'floor')
{
this.touchingGround = true;
}
});
};
Sorry if this is a really easy fix or just doesn't work and I'm being stupid.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
