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

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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

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