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

cell_y_sort == true in TileMap breaks body_shape on collision with Area2D #48603

Open
Tracked by #45334
Flamebeard10339 opened this issue May 10, 2021 · 1 comment
Open
Tracked by #45334

Comments

@Flamebeard10339
Copy link

Flamebeard10339 commented May 10, 2021

Godot version:

Godot 3.3-stable

OS/device including version:

Windows 10
GLES3
Nvidia GeForce RTX 2060 with Max-Q design (laptop)

Issue description:

If you configure an Area2D to emit the body_shape_entered (or exited) signal when it collides with a TileMap that has y sorting enabled the 'body_shape' parameter of the body_shape_entered method will always be 0 (as opposed to the index of the tile in the TileMaps.get_used_cells() array).

I do not know if this is expected/supported behavior.

unrelated context as to how i found this bug
I was trying to make a demo game involving a hexagonal grid based tilemap and was happily coding it such that the tilemap has a halfoffset for the hex tiles etc..., when I realized that instead of doing the whole rigmarole of calculating where the hex tile is compared to the underlying grid (see: https://godotengine.org/asset-library/asset/406) I could instead cheat by using collisions. Since this would only be a demo i figured I could cheat a little, and to my amazement it worked. five lines of code and Bam! I had it such that the tiles would detect the mouse. This works flawlessly, until suddenly it didn't (as usual). After some debugging I realized that the y-sort variable breaks my method of detecting which tile in the tilemap had collided.

Steps to reproduce:
Create a Node2D
Add a TileMap child
Add a Area2D with a CollisionShape2D

In the TileMap, add a tileset.
Add a New Single Tile to the tileset and give it a region and a collision shape (whole area, or partial area)
Paint at least 2 tiles into the world

Connect the body_shape_entered signal of the Area2D

Add a script the the Area2D:

extends Area2D

func _process(delta):
position = get_global_mouse_position()

func _on_mouse_follower_body_shape_entered(body_id, body, body_shape, local_shape):
    print("body_shape: %s" % [body_shape])

Run the program and mouse over the tiles

you should see:
body_shape: 2
body_shape: 1
body_shape: 4
body_shape: 5
body_shape: 7

or some variation

then go back into the project and check the option Y Sort (property cell_y_sort) in the Tilemap

run the program and mouse over the tiles

you should see:
body_shape: 0
body_shape: 0
body_shape: 0
body_shape: 0
body_shape: 0

Minimal reproduction project:

I attached a minimal reproduction project. Hopefully it works for you. Sorry if I wasn't descriptive enough at any point, I've never done something like this before. If this is actually intended behavior I would appreciate a link so that I could remedy my ignorance.
temp.zip

@pouleyKetchoupp
Copy link
Contributor

Confirmed in both 3.3 stable and 3.2.3 stable.

@groud groud modified the milestones: 3.3, 3.4 May 24, 2021
@akien-mga akien-mga modified the milestones: 3.4, 3.5 Nov 8, 2021
@KoBeWi KoBeWi modified the milestones: 3.5, 3.x Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants