It seems that the moveWithCollisions method works with the position of the mesh at the start of the frame, rather than at the time of the call to it. Calling moveWithCollisions twice in one frame causes the second call to handle collisions as if the first call had not happened. I wonder if there’s anything that can be done between calls to moveWithCollisions to avoid this issue.
This issue is demonstrated by this playground.
Run the playground and note the starting position of the spheres. Hit the “space” key once and it’ll move all the three spheres. The first (red) moves as expected, the other two (magenta & yellow) do not.
The first (red) sphere starts straight above its own ground mesh (which is also red). Its moveWithCollisions method is called to move it straight down through its ground mesh. This causes it to collide with the ground mesh and it stops when (and where) this occurs.
The second (magenta) sphere starts straight above its own ground mesh (also magenta). In this case, moveWithCollisions is called to moved it across to where there is no ground mesh beneath it. moveWithCollisions is then called a second time to move it straight down through the y-position of its ground mesh (like the first, red one). What is expected is that it would travel the full length down, since there is no ground to block movement. What is observed instead is that it reacts as if it is still over its ground, since that’s where it was at the start of the frame. It moves down until it is blocked by it’s ground and then it stops.
The third (yellow) sphere starts in a place where there is no ground mesh beneath it. moveWithCollisions is called to move right over its own ground mesh. Then moveWithCollisions is called again to move it down past its own ground mesh. What is expected is that the sphere would collide with its ground mesh during its second call to moveWithCollisions, since it is moving through it at that time. What is observed instead is that it moves straight through its ground mesh with no collisions stopping it. This is because at the start of the frame it was NOT over its ground at all, so the second call to moveWithCollisions thinks it is still not over its ground mesh, even though the first call moved it into that position.
This issue is especially important now that moveWithCollisions can be called with different parameters for different effects, so combining all movement into one call to moveWithCollisions is not always feasable. I wonder if there’s anything I can do to update a mesh’s final position between the first and second calls to moveWithCollisions.