Jump to content

P2 physics Contactmaterial not working - Please help :(


Recommended Posts

Hello everyone, this is my first time posting on this forum, which means I'm pretty desperate at this point haha!

I'm trying to make a simple game where a character is sliding down a hill, this is what I got so far: http://chewyrabbit.com/game.php
I want to make the hill as slippery as ice, just like some ice parts in this game: http://test.xapient.net/phaser/ALL/ I learned a lot from this game btw. I tried to copy how the user made his ice material, but it doesn't seem to work in my game!

// Create ramp and player from tiles
sharp = this.game.physics.p2.convertCollisionObjects(map,"points");
player = this.game.add.sprite(10,10, 'player');

// Define materials
groundMaterial = this.game.physics.p2.createMaterial();
playerMaterial = this.game.physics.p2.createMaterial('player');

// Give the ramp material
for (i=0; i<sharp.length; i++){
// define what happens when one material contacts the other
this.game.physics.p2.createContactMaterial(playerMaterial, groundMaterial, { friction: 0 , restitution: 0 });

What am I doing wrong? Please help me :( 

Link to comment
Share on other sites

So because it took the mods a 100 years to approve my question, I found out something by myself:

update: function() {
		//  Reset the players velocity THIS PART
        //  player.body.velocity.x = 0;

		if (cursors.left.isDown)
		//  Move to the left

		else if (cursors.right.isDown)
		//  Move to the right

		//  Stand still

		player.frame = 4;

		// Jump!
		if (cursors.up.isDown && this.game.time.now > jumpTimer && checkIfCanJump(this.game))
		    jumpTimer = this.game.time.now + 750;


In the function where the player's movement is controlled, the player's default velocity is set to 0. When I delete that part, the player slides pretty smoothly down the hill. 

But! I still can't seem to apply material to the player, no matter what I try. The material just seems to be ignored. I get no errors though.

So how can I succesfully apply material / contactmaterial to the player?

Link to comment
Share on other sites


  • Recently Browsing   0 members

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