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

Chapter 61 (Section 5.19) Movement System Teleporting Error #188

Open
andreasschmitz opened this issue Mar 29, 2022 · 0 comments
Open

Chapter 61 (Section 5.19) Movement System Teleporting Error #188

andreasschmitz opened this issue Mar 29, 2022 · 0 comments

Comments

@andreasschmitz
Copy link

I am wondering if there is an error in chapter 61, which introduces the new movement system.

In the Apply teleports part, we first check if the depth of the teleport and the map's depth are the same. If that's not the case and we are not moving the player, the entity is teleported to another map, as depicted in the following code.

for (entity, teleport) in (&entities, &apply_teleport).join() {
    if teleport.dest_depth == map.depth {
        // omitted
    } else if entity == *player_entity {
        // omitted
    } else if let Some(pos) = position.get(entity) {
        // [...]
        crate::spatial::move_entity(entity, idx, dest_idx);
        other_level.insert(entity, OtherLevelPosition{
            x: teleport.dest_x,
            y: teleport.dest_y,
            depth: teleport.dest_depth })
            .expect("Unable to insert");
        position.remove(entity);
    }
}

Please correct me if I am wrong, but I think we need to remove the entity from the spatial map (crate::spatial::remove_entity) instead of moving it, right? It is not anymore part of the current map. This problems sorts itself out the next time MapIndexingSystem runs, but succeeding systems of the current loop would still see incorrect information.

I am happy to create a pull request with the necessary changes, in case I am right with my assessment.

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

1 participant