Chewyrabbit Posted November 22, 2016 Share Posted November 22, 2016 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++){ sharp[i].setMaterial(groundMaterial); } // 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 More sharing options...
Chewyrabbit Posted November 23, 2016 Author Share Posted November 23, 2016 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 player.body.moveLeft(150); player.animations.play('left'); } else if (cursors.right.isDown) { // Move to the right player.body.moveRight(150); player.animations.play('right'); } else { // Stand still player.animations.stop(); player.frame = 4; } // Jump! if (cursors.up.isDown && this.game.time.now > jumpTimer && checkIfCanJump(this.game)) { player.body.moveUp(800); 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? Hans 1 Link to comment Share on other sites More sharing options...
Recommended Posts