Jump to content

Collision behaving oddly


Zampano
 Share

Recommended Posts

Hello everyone,

I've got a very odd problem with the collision detection of the arcade physics system. The code is as follows:

 

var x_player = null;
var floor = null;
	
BasicGame.Game.prototype = {
		
	preload: function () {
		
	},
 
    create: function () {
	
		this.physics.startSystem(Phaser.Physics.ARCADE);
		
		var boundary_bottom = 650;
		var boundary_top = 50;
		
		
		floor = this.add.sprite(640, 680, 'floor');
		floor.anchor.setTo(0.5, 0);
		
		x_player = this.add.sprite(640, 450, 'x_player');
		x_player.anchor.setTo(0.5, 0.5);
		
		
		this.physics.arcade.enable([floor, x_player]);
		
		
		floor.body.allowGravity = false;
		floor.body.immovable = true;
		x_player.body.gravity.y = 600;
		x_player.body.bounce.y = 0.4;
		x_player.body.setCircle(27,9,9);
	
    },

    update: function () {

		this.physics.arcade.collide(x_player, floor);
		
		if (this.input.activePointer.isDown)
		{
			x_player.body.velocity.y = -500;
		}
    },

	render: function () {
		this.game.debug.body(x_player);
		this.game.debug.body(floor);
	}
};

The collision detection seems to work basically, but when I let the ball jump by pressing the mouse button, there is a pretty big random chance it will just slip through the floor when it comes down again.

It seems like it doesn't work precisely enough or something. Does anyone know more?

Help is greatly appreciated!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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