kaplayjs / kaplay

🦖 A JavaScript/TypeScript Game Library that feels like a game, fun
https://kaplayjs.com
MIT License
564 stars 36 forks source link

bug: level raycast is messed up when the tiles don't have `topleft` anchor #445

Open dragoncoder047 opened 1 month ago

dragoncoder047 commented 1 month ago

add to mazeRaycastedLight example

const level = addLevel(
    createMazeLevelMap(15, 15, {}),
    {
        pos: vec2(100, 100),
        tileWidth: TILE_WIDTH,
        tileHeight: TILE_HEIGHT,
        tiles: {
            "#": () => [
                sprite("steel"),
                tile({ isObstacle: true }),
+               anchor("center"),
            ],
        },
    },
);

const bean = level.spawn(
    [
        sprite("bean"),
        anchor("center"),
        pos(32, 32),
        tile(),
        agent({ speed: 640, allowDiagonals: true }),
+       anchor("center"),
        "bean",
    ],
    1,
    1,
);

and the raycasted light bubble will be in the wrong spots

dragoncoder047 commented 1 month ago

Also, it doesn't obey area scales

mflerackers commented 1 month ago

This is because it is a voxel raycaster, it traces rays along the voxels of the level (the grid) and looks only at grid tiles which are hit. This example is set up to render some tiles as solid. These tiles lie on the grid, it doesn't matter where the sprite is. It doesn't look at the sprite. The raycaster only sees solid tiles and areas, not sprites.