appsinacup / godot-rapier-physics

Godot Rapier Physics – 2D and 3D physics engine for the Godot game engine. with better stability, performance, liquids, determinism, state serialization and no ghost collisions.
https://godot.rapier.rs
MIT License
392 stars 20 forks source link

`Shape not found` error when assign polygon to CollisionPolygon2D after update to version 0.8.7 #288

Open 949886 opened 1 week ago

949886 commented 1 week ago

Describe the bug

Screenshot - 2024-10-18 21 11 13

image

It worked fine before I updated it to the new version.

To Reproduce

class_name RigidBodyGenerator
extends RigidBody2D

@onready var sprite = $Sprite2D

func _ready() -> void:
    var bitmap = BitMap.new()
    bitmap.create_from_image_alpha(sprite.texture.get_image())
    var polys = bitmap.opaque_to_polygons(Rect2(Vector2.ZERO, sprite.texture.get_size()), 0.5)

    for poly in polys:
        var collision_polygon = CollisionPolygon2D.new()
        collision_polygon.build_mode = CollisionPolygon2D.BUILD_SEGMENTS
        collision_polygon.polygon = poly
        add_child(collision_polygon)

        # Generated polygon will not take into account the half-width and half-height offset
        # of the image when "centered" is on. So move it backwards by this amount so it lines up.
        if sprite.centered:
            var half_size = bitmap.get_size() / 2
            collision_polygon.position -= Vector2(half_size.x, half_size.y)

Expected behavior

No errors.

Environment:

Example project(zip)

game.zip

Ughuuu commented 1 week ago

Can you also try in 0.8.8?

949886 commented 1 week ago

Can you also try in 0.8.8?

I tried it in version 0.8.8 and the errors disappeared, but the collide behavior is different from before. Is that normal?

image


This is the old one:

image

Ughuuu commented 1 week ago

Ok, so now errors dissapear but the behaviour seems wrong. Will investigate the behaviour for collisions.