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

Don't use CollisionGenerationMethod.Fast in open shapes #167

Merged

Conversation

limbonaut
Copy link
Collaborator

Fixes #164

@limbonaut limbonaut added the bug Something isn't working label Jun 21, 2024
@limbonaut limbonaut requested a review from mphe June 21, 2024 16:38
@mphe
Copy link
Collaborator

mphe commented Jun 21, 2024

Not really a fix but a quick workaround. An actual fix would be to generate a closed curve. But I think this workaround suffices for the two people actually using open shapes.

Edit: Just wanted to suggest to update the doc comment and suddenly a new commit is pushed :D

@limbonaut limbonaut force-pushed the dont-use-fast-collisions-in-open-shapes branch from 2b6a0df to 43c6e8c Compare June 21, 2024 16:46
@mphe mphe merged commit 355778e into SirRamEsq:master Jun 21, 2024
1 check passed
@mphe
Copy link
Collaborator

mphe commented Jun 21, 2024

Thanks for fixing!

@limbonaut
Copy link
Collaborator Author

limbonaut commented Jun 21, 2024

@mphe I actually use open shapes 😅 , but in a rather unusual manner - secret areas:

image
That's how I discovered this issue.

@mphe
Copy link
Collaborator

mphe commented Jun 21, 2024

How exactly? (hard to see on the picture)
I use closed shapes for secret areas but without "solid" collisions, so you can walk through them and they fade out.

@limbonaut
Copy link
Collaborator Author

@mphe, I use smash-to-reveal areas like this:

cover-demo.webm

@limbonaut
Copy link
Collaborator Author

I've posted the code on discord some time ago - if you search for "secret area" you'll find it.

@mphe
Copy link
Collaborator

mphe commented Jun 21, 2024

Ahh ok, so there is an open shape with a closed one without edges attached. In such cases I usually use one shape and set material overrides on respective edges to "don't render".

@limbonaut
Copy link
Collaborator Author

Not exactly, the cover is a Polygon2D with a script.

@tool
## Script that manages a "cover" (see below). Updates are performed when transform is changed.
## It doesn't deal with rotations.
## Note: Not the full source code.

@export var sync_shape: SS2D_Shape

## `cover` is a Polygon2D that syncs its own fill texture to the SS2D's.
## It serves as an overlay that can be put on top of an SS2D and cover a "secret" area.
@onready var cover: Polygon2D = $Editable/Cover

func _notification(p_what: int) -> void:
    if p_what == NOTIFICATION_TRANSFORM_CHANGED:
        _update_cover_offset()

func _update_cover_offset() -> void:
    if not sync_shape:
        return

    for i in cover.polygon.size():
        cover.polygon[i] += cover.global_position
    cover.global_position = Vector2.ZERO

    var offset: Vector2 =  sync_shape.global_position - cover.global_position
    cover.global_position = sync_shape.global_position
    for i in cover.polygon.size():
        cover.polygon[i] -= offset

@limbonaut limbonaut deleted the dont-use-fast-collisions-in-open-shapes branch June 21, 2024 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bad collision generation in open shapes with CollisionGenerationMethod.FAST
2 participants