kaplayjs / kaplay

🦖 A JavaScript/TypeScript Game Library that feels like a game. Make games fast, fun and fanstastic.
https://kaplayjs.com
MIT License
436 stars 32 forks source link

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

Open dragoncoder047 opened 3 days ago

dragoncoder047 commented 3 days 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 3 days ago

Also, it doesn't obey area scales

mflerackers commented 3 days 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.