godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.58k stars 21.09k forks source link

CharacterBody2D giving wrong floor normal when walking across the apex of a CircleShape2D #68903

Open JoannesJ opened 1 year ago

JoannesJ commented 1 year ago

Godot version

4.0 beta5 (89a33d28f)

System information

Ubuntu 22.04.1

Issue description

Examining the return value of get_floor_normal on a CharacterBody2D with the template script for movement, sometimes returns a wrong normal when walking across the apex of a CircleShape2D.

Steps to reproduce

Running the scene in the attached project: A CharacterBody2D will drop on a StaticBody2D with a CircleShape2D. When colliding, a pink line will be drawn to indicate the floor normal. The floor normal will be pointing to the side, while a straight up normal is expected. Screenshot from 2022-11-19 22-47-59

You can jump in place, and sometimes the correct normal will show. You can also walk back and forth around the apex and have brief flashes appear of the incorrect normal.

Minimal reproduction project

CollisionNormalTest.zip

Sauermann commented 1 year ago

I tracked this problem to https://github.com/godotengine/godot/blob/895428c8058ce97abb02a6a3500e463f72a4f9c9/servers/physics_2d/godot_collision_solver_2d_sat.cpp#L319 where it looks like supports_A receives wrong content in the following lines.

rburing commented 1 year ago

This seems to be an internal numerical precision issue, since the problem doesn't occur in a doubles build of the engine (compiled with the float=64 SCons option). In particular, a workaround is to use a float=64 build of the engine.

AttackButton commented 1 year ago

With the CollisionShape2D rectangle shape is working correctly. I think this normal issue calculation just happens with capsules and probably other shapes.

for this test:

image

normals_issue