Ashley wrote somewhere that collisions are something we have to handle ourselves in javascript. He also wrote that internally a collision is "is overlapping & wasn't overlapping previous frame" but that doesn't appear to be the entire story.
Example: The platform behavior lands on solid ground. With events this correctly triggers a collision, makes sense. But in javascript with just a testOverlapSolid() it never triggers. So without tearing open the platform behavior again, I have to assume that there is a piece of code that roughly does:
1. Execute the movement
2. testOverlapSolid() -> if true trigger collision
3. Push out solid
So when my scripts are executed, the platformer object will just never be overlapping the solid. So I came up with this, which sort of works
const sprites = runtime.objects.Sprite;
for(const i of sprites.instances()) {
const vec = {
"x": i.behaviors.Platform.vectorX,
"y": i.behaviors.Platform.vectorY
}
const prev = {
"x": i.x,
"y": i.y
}
i.offsetPosition(vec.x*runtime.dt, vec.y*runtime.dt);
if(i.testOverlapSolid()) i.setAnimation("Animation 2");
i.setPosition(prev.x, prev.y);
}
At least I think it does what I want it to. I have to be cautious to only execute this code after any potential changes to the vectors (e.g. jumping, knockback) which is fine.
The main issue I'm having is that this technically triggers the collision a frame to early. So I kinda need to only register the collision first, and then handle what it should do the next frame. Is this the right approach? My gut feeling tells me this might be prone to a bunch of edgecases but maybe I'm mistaken...
Of course I could possibly also just handle this in events, but that's not the point :V