Matter-js: How to avoid vertical friction with static bodies

Created on 22 Nov 2018  路  4Comments  路  Source: liabru/matter-js

I'm developing a simple game and creating some static objects for world boundaries. I also have a body as a player that I move across the scene from the left to the right and jump reaching some platforms. Yes, another platform game but for demo purposes. Everything seems to be normal but when the player falls down and collide with a wall friction doesn't allow gravity to appear. It is something very strange, I suppose I should have the same behavior with floor items but they work as expected and the player goes from one side to the other without any friction.

Here is the player configuration:

Bodies.rectangle(50, 100, 32, 32, { inertia: Infinity });

And here for the left wall:

Bodies.rectangle(x, y + 8, 2, 16, { isStatic: true })

How can I avoid that friction when jumping and falling down?

question

All 4 comments

Hi guys,

I've found why is this happening but not the solution. If you set "inertia" to Infinity value to a box it will have friction with other boxes sides. The following jsFiddle shows it. Do you know how to avoid this behavior? Am I doing something wrong or missed something?

Matter.js vertical friction test link

Regards.

I've ran into the same issue. Michael Hadley solves this issue (which he calls spiderman-ing) in this tutorial by attaching two additional sensor collision boxes to the left and right of the main collision box. When the sensor collision box collides with something, the main body is moved such that it does not collide but the sensor still collides. This effectively avoids the vertical friction.

However, this seems more like a work-around then an actual solution to the problem...

I have exactly the same issue.

Setting friction to zero on a static body still applies friction to any colliding bodies. This doesn't seem right 馃

Any bodies that are in contact will have friction between them, it doesn't matter what the orientation is, so you'll need to add some custom logic for this. I think one solution for this is to use a thin sensor at the player's 'feet' that turns the player's body.friction on only when it is in collision with a 'ground' body, but the sensor should not overlap the left and right edges of the player, only the bottom edge.

It's almost possible to use compound body parts to do this, but unfortunately they don't allow for different friction values per-part (you could maybe try patch this in Pair.update to use bodyA rather than parentA etc, it might work).

Setting friction to zero on a static body still applies friction to any colliding bodies.

Try setting the friction again after the static body creation, because by default static bodies have their friction set to 1.

Was this page helpful?
0 / 5 - 0 ratings