godotengine / godotengine/godot

Unexpected normals when colliding with Tilemap

Open
#90,067 4 comments 0 reactions 0 assignees View on GitHub
discussion documentation enhancement needs testing topic:2d topic:physics
Dominant language
C++
Stars
117k
Forks
26.8k
PR merge metrics
PR metrics pending

Description

### Tested versions

- Reproduced in 4.3 Dev 5
- Reproduced in 4.2.1 Stable

### System information

Godot v4.2.1.stable - Windows 10.0.19045 - Vulkan (Mobile) - dedicated AMD Radeon RX 6600 XT (Advanced Micro Devices, Inc.; 31.0.22023.1014) - AMD Ryzen 5 5600X 6-Core Processor (12 Threads)

### Issue description

While creating a node to monitor contacts on a CharacterBody2D I've noticed that raycasts that are going downward are sometimes being reported as having a horizontal normal. This should not be possible, the tilemap is a flat surface with many boxes, but with no gaps between the tiles. This happens in every direction, but for simplicity i'll focus on when it happens moving downwards.

I think the raycast is clipping through the corner of one tile, and into the wall of a surrounding tile somehow.

![image](https://github.com/godotengine/godot/assets/4250341/15a1c269-aba5-4835-9409-344c1aeda815)
In the above snippet of the repro project, the white arrows show the general direction of the raycasts.

And on some frames the following normal occurs sometimes. (the direction of the red arrow shows the normal, which shouldn't be possible with a circle colliding on a flat surface.)
![image](https://github.com/godotengine/godot/assets/4250341/8b5567f9-5aa0-4d2f-b075-d201f2f3d01f)

Sorry, wish I could explain it a bit better but I hope the images and project help to realize the issue here.

I've isolated the contact checker script and made a reproduction of the issue.

(Also, is there no way to get contacts for Characterbody2D nodes? It feels like getting contacts on these nodes would be a very common usecase, with no obvious solution. And its even more confusing considering the tilemap tutorial mentions adding data to tiles that would need to be accessed through querying contacts.)

Here is a screenshot of the issue occurring at runtime.
![image](https://github.com/godotengine/godot/assets/4250341/c357aee2-447d-471f-9fba-116129ad1ee3)

### Steps to reproduce

Rub a colliding body against a flat tilemap's surface and shoot a raycast at the colliding points. Occasionally a completely incorrect normal will be reported.

### Minimal reproduction project (MRP)

[reproduction_normalissue.zip](https://github.com/godotengine/godot/files/14814817/reproduction_normalissue.zip)

Contributor guide

Open the contributing guide

Research direction

Start by running the linked reproduction_normalissue.zip project and follow the steps for rubbing a colliding body against the flat tilemap surface. Inspect the CharacterBody2D contact-checking and raycast behavior shown in the reproduction; done means downward and other directional raycasts consistently report normals matching the contacted surface.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, godot
Domain
game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.