Jump to content

physics collider not working. [phaser]


Recommended Posts

// hello again lads! I've got another problem. I was working on a game and I was specifically  

// working on a Gameplay scene and there was no specific error in the console but the physics  

// collider between my platform and the player wasn't working and my player fell through the 

// platform. Can somebody point out the mistake I've made? Any help will be greatly appreciated :)

// The code from my 'Gameplay' scene:

var platform;
var player;

class gamePlay extends Phaser.Scene{
		super({key: 'playing'});


		this.load.image('sky', 'assets/sky.png');
		this.load.image('sun', 'assets/sun.png');
		this.load.image('ground', 'assets/platform.png');
			{frameWidth: 32, frameHeight: 32}

		this.add.image(400, 300, 'sky');
		this.add.image(400, 100, 'sun');

		platform = this.physics.add.staticGroup();

		platform.create(400, 500, 'ground');
		platform.create(250, 500, 'ground');
		platform.create(500, 500, 'ground');

		player = this.physics.add.sprite(400, 300, 'cubey');

		this.physics.add.collider(player, platform); // not working





Edited by AmbitiousIndie
Link to comment
Share on other sites

Instead of defining `player` from a `var` keyword, try defining it in the class you called using:

class example extends Phaser.Scene {

  constructor() {



  create() {

    this.player = this.physics.add.sprite(x, y, "key");

    this.physics.add.collider(this.player, this.collidingThing);



Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...