Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Differences in FOV calculation depending on position #218

Open
scalemaildev opened this issue Apr 21, 2024 · 1 comment
Open

Differences in FOV calculation depending on position #218

scalemaildev opened this issue Apr 21, 2024 · 1 comment

Comments

@scalemaildev
Copy link

scalemaildev commented Apr 21, 2024

I've noticed that the FoV calculation puts out different results based on the source position. For example, in these two images: standing on the bones in the lower left allows the player to see the hex next to the bones in the upper right. However, standing in that same spot in the second image doesn't allow the player to see their original position.

cornercase1
cornercase2

Is this normal behavior? I'm using pointy-topped hexes with double wide coordinates, and the topology is set to 6.

Code snippet for how I'm implementing fov:

updateVis(scene: any, entity: Entity): void {
        const vis = new Set<number>();
        const viewPosC = intToCoord(entity.c.e.pos);
        const px = viewPosC[0];
        const py = viewPosC[1];

        const fov = new FOV.PreciseShadowcasting((x: number, y: number): boolean => {
            const pos = coordToInt([ x, y ]);
            return scene.currentLevel.tiles[pos] && !scene.currentLevel.tiles[pos].c.e.blocksSight;
        }, { topology: 6 });

        fov.compute(px, py, entity.c.mem.visRadius, (xi: number, yi: number) => {
            const pos = coordToInt([ xi, yi ]);
            vis.add(pos);
        });

        entity.c.mem.vis = vis;
    }
@ondras
Copy link
Owner

ondras commented Apr 21, 2024

Yeah, I am afraid this is just the way it is. The algorithm is not symmetric, i.e. "you see B from A" does not imply "you see A from B".

I understand that this might not be ideal for some games, but I am not aware of any straightforward way (algorithm modification) to enforce the rule.

Visibility in general is complex and hard. See https://www.reddit.com/r/Damnthatsinteresting/comments/1agtkaj/optimal_distance_to_peek_in_shooter_games/ for an interesting example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants