How to avoid vertical friction with static bodies
See original GitHub issueI’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:
- Created 5 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 thanparentA
etc, it might work).Try setting the friction again after the static body creation, because by default static bodies have their friction set to
1
.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…