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

Add "Collisions" enabling property for tilemaps layers, which allows to respect collision shapes regardless of visibility state #6405

Open
paweljarosz opened this issue Feb 14, 2022 · 2 comments
Labels
feature request A suggestion for a new feature physics Issues related to physics (2D and/or 3D) tilemap Issues related to tilemaps

Comments

@paweljarosz
Copy link
Sponsor Contributor

Background topic on forum: https://forum.defold.com/t/tilemap-collisions-not-working-when-layer-is-invisible/64653

Problem:
When one is using two layers for game - one to represent collisions (often with basic shapes, like square or triangle) and one to represent visually the level (often with various shapes and edges), sometimes can happen, that visual representation layer is not covering the background collision layer, even if I set collision layer z under visual layer (mainly because of artistic vs practical aspects).
Problem is, that even if we make collisions on separate layer, we can not switch its visibility, because collision shapes are then not respected by physics engine.

Workaround:
To prevent this I can use different image(tilesource) for collision source and different for visual tiles. However for large maps/sources and in the development phase (when map can change a lot) this is cumbersome, as I always need to remember about eventually updating collision tilesource. Even though collision tiles are few, I can't make a smaller image for tilesource and reuse it for all visual representation, because the two tilesources (for collisions and visual representation) must have matching dimensions.

Idea:
One solution would be to allow to disable visibility of a layer (e.g. collision layer), without affecting collision shapes. For now there is only one property for visibility for tilemaps layers: Visible

It would be great to add another boolean property here for tilemaps layers called for example: "Collisions"
which if set to true, will tell physics engine to respect collision shape of the layer, regardless of property "Visible".

In this setup we could make a layer with collision shapes according to the tilesource, but the layer will not be visible in game ("Collisions": true, "Visible": false)

P.S. Another helping solution would be to allow tilesources of different sizes to be in tilemap for collisions (but row size must be identical, so order is maintained).

@paweljarosz paweljarosz added the feature request A suggestion for a new feature label Feb 14, 2022
@paweljarosz
Copy link
Sponsor Contributor Author

One issue I had writing this issue, is that I don't know exactly what is causing collision shapes to be taken into consideration by physics engine and why it's affected by Visible property of the layer (why no collision shapes are taken into consideration for physics engine if layer is not visible). If it could be decoupled, than I hope adding another property to control it, could be a good solution as presented above.

@britzl britzl added physics Issues related to physics (2D and/or 3D) tilemap Issues related to tilemaps labels Feb 14, 2022
@CrazyAmphibian
Copy link

./engine/gamesys/src/gamesys/scripts/script_tilemap.cpp might be worth looking at. i know nothing about C++, but i noticed stuff around the range of line 489 that might be helpful

        bool visible = lua_toboolean(L, 3);
        SetLayerVisible(component, layer_index, visible);

        dmMessage::URL sender;
        if (dmScript::GetURL(L, &sender))
        {
            // Broadcast to any collision object components under this game object
            // TODO Filter broadcast to only collision objects
            dmPhysicsDDF::EnableGridShapeLayer ddf;
            ddf.m_Shape = layer_index;
            ddf.m_Enable = visible;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request A suggestion for a new feature physics Issues related to physics (2D and/or 3D) tilemap Issues related to tilemaps
Projects
None yet
Development

No branches or pull requests

3 participants