question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to avoid vertical friction with static bodies

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
liabrucommented, Jan 13, 2019

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.

1reaction
Tommsy64commented, Dec 24, 2018

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…

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Surprisingly Cool Physics of Pushing a Block Against a Wall
First, since the force is pushing at an angle the x component decreases. This means the normal force also decreases, which decreases the ......
Read more >
Slipping – Body Physics: Motion to Metabolism
Push the object with your hand, but not hard enough to make it slide. At this point static friction is reacting to your...
Read more >
Dynamics | University Physics - Lumen Learning
Notice that the acceleration of the couch in the vertical direction must be zero ... The person is not pushing hard enough to...
Read more >
What is friction? (article) | Khan Academy
You may push harder and harder on the crate and not move it at all. This means that the static friction responds to...
Read more >
6. FORCE AND MOTION - II
Note: The friction between car tires and the road is static friction. This friction is crucial when you try to stop a car....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found