Open HildericSB opened 7 years ago
See comments in #334 which solve a similar issue.
You think it's a friction problem ? I don't get it ( sory i'm not really good about physics ). For me, the body that goes upward should not collide on Y abscisse, but just on his X.
Are you saying it's colliding as if the block was overhanging, but it's not? A jsfiddle example would help here!
I'll try do to a JS fiddle. I'll try to copy this demo https://codepen.io/tanker837/pen/qaeQKZ for the movement. In this demo the player movement is set with force.x or force.y, and I use the setVelocity fn. It's may be better to use the force system ?
And do you know some other good examples of platformer games made with matterJS ?
Thanks for you help !
It depends on what the issue is, if it's what I think you're saying then there might be a bug. The velocity approach is a good one when you need precise movement (like a platformer player), the force approach is useful when you have a body that accelerates or turns more slowly (like a car).
The demo you linked is a great one though. I should probably do a more simple platform game example myself though!
It's hard to know if it's a bug, or if it's juste because I use badly the engine. I really should give you an example. The force approach (like in the linked demo) is a bit strange for a platformer. But I don't find example with velocity approach.
A simple example of a platform game could be awesome ! I would really like it.
I finnaly got an example !
https://jsfiddle.net/hsassewa/
On the gif, the player body seems to get stuck between the others smaller body. How to avoid that ?
Thanks for the example, this might take some investigation as to whether it's a bug and if it's possible to solve in the engine.
Until then it looks like you're on the right approach to a good solution: check the direction is clear before moving there. A good way might be to try using Query.ray from the edge of the body's bounds along the velocity vector.
Another method you could try is to find all the current collisions for the player, then loop through them, find the vector between the player and the colliding body. Then dot product this with the collision.penetration
vector and prevent movement if they're near parallel.
Hum so there is so there is no simple solution :/ I should try your second solution, and try to prevent movement if they're near parallel.
I experienced this as well. I shaped the player's body to have angles at the bottom to avoid the problem.
https://landgreen.github.io/sidescroller/ Press T to enter testing to see the player shape.
Hum that's an interesting work around !
It is and you could probably use { chamfer: 8 }
to get a similar effect easily?
Seems much better but still not perfect : https://jsfiddle.net/hsassewa/2/
@hilde2 Did you find a good solution? Here is my current approach: https://jsfiddle.net/a7wjrh4u/2 . Movement: wad
The { chamfer: 8 }
(thanks @liabru) helps a bit, but not completely. Another trick would be to simply not stack static bodies, and instead have a big one, like this: https://jsfiddle.net/a7wjrh4u/8 .
I'm not sure if movement is correctly done, the jumping feels a bit strange.
@hilde2 for your first pictures you could try putting the static bodies into each other, like this: https://jsfiddle.net/a7wjrh4u/9/
Hi !
I'm trying to do a platformer game with matter.js.
And I got trouble when pressing right key, that set Body.setVelocity X to -10 and jumping that set Body.setVelocity Y to -10. The problem is that the body enter slightly in the body next to him even with :
inertia : Infinity, frictionStatic : 0, friction : 0, slop : 0,
So because of this, the body collide with a body above him, and it should not. It' supposed to "glide" on the other body.Img :![sans titre](https://cloud.githubusercontent.com/assets/24705209/21451089/a3d3fe9a-c8fc-11e6-82e1-30497c83646b.png)