SirRamEsq / SmartShape2D

A 2D Terrain Tool for Godot
MIT License
1.34k stars 67 forks source link

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

Closed limbonaut closed 4 months ago

limbonaut commented 4 months ago

Fixes #164

mphe commented 4 months ago

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

mphe commented 4 months ago

Thanks for fixing!

limbonaut commented 4 months ago

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

image That's how I discovered this issue.

mphe commented 4 months ago

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 commented 4 months ago

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

cover-demo.webm

limbonaut commented 4 months ago

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

mphe commented 4 months ago

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 commented 4 months ago

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