Jump to content

Tipping/slide effect: gravity doesn't work


casey
 Share

Recommended Posts

I have a platform where the platform will start tipping (rotating) when the player jumps on it, tipping the player off. 

The platform rotates now, but the player's gravity doesn't come into effect when the platform rotates--the player stays standing in the air. 

I can disable the platform body, and the player will fall through, but I want the player's body to move along the platform (slide off). What am I missing?

var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update });

function preload() {

    game.load.image('ground', 'platform.png');
    game.load.spritesheet('dude', 'dude.png', 32, 48);

}

var player;
var ledge;

function create() {

    game.physics.startSystem(Phaser.Physics.ARCADE);

  	ledge = game.add.sprite(0, 400, 'ground');
	player = game.add.sprite(20, 20, 'dude');
	
	game.physics.arcade.enable([ledge, player]);
	
    ledge.body.immovable = true;
    ledge.body.allowGravity = false;

    player.body.gravity.y = 200;
	
	cursors = game.input.keyboard.createCursorKeys();
	
}


function update() {
	
 this.physics.arcade.collide(player, ledge);

	 player.body.velocity.x = 0;

    if (cursors.left.isDown)
    {
        player.body.velocity.x = -150;
    }
    else cursors.right.isDown)
    {
        player.body.velocity.x = 150;
    }
   
		
	//when player goes half way start sliding
	if(player.body.x > 200){
		ledge.angle += 0.5;
		//ledge.body.enable = false;
	}

}

 

Link to comment
Share on other sites

Arcade Physics is a system based on AABB collision detection, every sprite has a rectangular body shape and it's not possible to rotate it. You can observe that with render function below. For more advanced physics like slopes, you could use P2 Physics. 

function render() {
    game.debug.body(ledge);  
}

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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