Hi,
I have only found stuff online that tells you to destroy. I have implemented that in my game, but the problem is that when I respawn the player I get an error message with the colliders that I am recreating.
In the create function I have code as below, to set up the player colliders:
this.playerColliders = [];
this.playerColliders.push(this.physics.add.collider(this.platformLayer, this.player));
this.playerColliders.push(this.physics.add.collider(this.enemygroup, this.player, this.hitPlayer,null,this));
When the player ‘dies’, I have code as below to destroy each one. This is for the effect of making the player fall off the screen without hitting anything.
this.playerColliders.forEach(collider => collider.destroy());
When I respawn the player, I am recreating each collider and adding back to the array, but I get the error as below:
Collider.js?b61a:161 Uncaught TypeError: Cannot read property 'removeCollider' of null
at Collider.destroy (Collider.js?b61a:161)
at eval (level1.js?faca:843)
at Array.forEach (<anonymous>)
at Level1.hitPlayer (level1.js?faca:843)
at World.collideSpriteVsGroup (World.js?b086:1961)
at World.collideHandler (World.js?b086:1839)
at World.collideObjects (World.js?b086:1732)
at Collider.update (Collider.js?b61a:143)
at World.step (World.js?b086:1021)
at World.update (World.js?b086:974)
What is the best way to handle this? Is there a way of making the player temporarily not be subject to collisions?