Jump to content

why my ground doesn't get friction?


Recommended Posts

Hey! This is my first thread, I'm new here, so hello everyone! :D

I started last week with phaser, and I am trying to test some features like extend the world, adding other sprites to background, adding a camera, all of this in the "game" that you make in this tutorial.

So now, I want to learn how friction works in platforms or ground. 

platforms = game.add.group();
platforms.enableBody = true;
var ground = platforms.create(0, game.world.height - 64, 'ground');
ground.scale.setTo(4, 2);
ground.body.immovable = true;
ground.body.friction.x = 0;

I want to set my ground like ice and that the player can slide, but it didn't work and I don't know why.

If there is no other code that involves "ground", maybe the problem is with the player sprite? :S

The version of phaser i am using is 2.9.4 btw.

Link to comment
Share on other sites

  • 3 weeks later...

Well, I think I was misunderstanding how friction works. 

In this thread, Samme said that friction is how much of one object's movement is transmitted to a second object that's riding it, but i didn't understand until I saw an example myself.

So this is what I did:

Didn't set to 0 the player velocity.x when the left or right key is up, but set a negative acceleration until the velocity.x is equal or less than 0, and then, set velocity.x and acceleration.x both to 0.

That gives the player the feeling of sliding through the ice, which is just what I wanted.

Maybe there is a better way to do it, but I don't know it xD

Link to comment
Share on other sites


  • Recently Browsing   0 members

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