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

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

Open
949886 opened this issue Oct 18, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@949886
Copy link

949886 commented Oct 18, 2024

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:

  • OS: Windows
  • Version: 0.8.7
  • Godot Version: 4.3
  • Type: 2d

Example project(zip)

game.zip

@949886 949886 added the bug Something isn't working label Oct 18, 2024
@949886 949886 changed the title Shape not found error when assign CollisionPolygon2D to RigidBody2D after update to version 0.8.7 Shape not found error when assign polygon to CollisionPolygon2D after update to version 0.8.7 Oct 18, 2024
@Ughuuu
Copy link
Contributor

Ughuuu commented Oct 18, 2024

Can you also try in 0.8.8?

@949886
Copy link
Author

949886 commented Oct 19, 2024

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
Copy link
Contributor

Ughuuu commented Oct 19, 2024

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

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

No branches or pull requests

2 participants