I am creating a simulation where blocks can slide according to gravity, but only along one axis (either x or y), like they're following a hidden groove or something (gravity changes). I've already locked their rotation so that they maintain their orientation (as noted here https://github.com/liabru/matter-js/issues/104), but I'm not sure what would work the best for maintaining position on a given axis.
Currently, I've set it up so that after each update, I reset the x (or y depending on the axis) to its initial value, which works fine when nothing collides, but as soon as another body collides, the colliding body sinks into the sliding block (since I'm manually moving back to where it has been pushed from). Is there a way to have a body maintain its axis during the collision step so that it doesn't move along one axis but is movable in the other?
Alternatively, would it make more sense to make the block static and move it accordingly to gravity manually instead of allowing it to collide like a non-static body?
Okay, so I found a way that works. I kept the broken implementation I described above, but added a static core to the sliding dynamic block that's slightly smaller. Each step, the static core updates its position to the dynamic block's position. This prevents colliding bodies from going into the sliding block, but allows the sliding block to behave in a dynamic way.
Sounds like a nice solution for now, but reopening this as a feature request as it would be nice to have!
Most helpful comment
Sounds like a nice solution for now, but reopening this as a feature request as it would be nice to have!