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

Incorrect overlap detections when manually moving CollisionObject2Ds in a single frame #18748

Closed
samdze opened this issue May 9, 2018 · 2 comments

Comments

@samdze
Copy link
Contributor

samdze commented May 9, 2018

Godot version:
Godot 3.0.2 official and Godot 3.0.3 RC1.

OS/device including version:
Windows 10 64 bit.

Issue description:
Inexistent intersections between KinematicBody2Ds and Area2Ds (untested with other configurations) occur when those nodes are manually moved through position or global_position not to be in contact.
The issue is best described below.

Steps to reproduce:
The reproduction project consist of a "character" node called KinematicBody2D that the player can move with WASD. The player can move between areas if he touches the "gates" (visible if "Visible Collision Shapes" is turned on) to the right and to the left of the current area or if he presses the left or right arrow keys.
Every area's contents are generated in code: gates and the object (which can be a collector or a collectable, if a collector, a KinematicBody2D, touches a collectable, an Area2D, the collectable object will trigger its "collected" animation and do a print).
Important: collector and collectable objects are always in the same position relative to the belonging area.
When the player changes area he is first repositioned in a free spot where no overlaps or collisions should occur, the areas are then all moved through position in such an order so that they never overlap, to make the current area the one in position (0, 0).

Actual results:
When the player changes area, the collectable object in the new current area gets collected by the collector object in the previous area, even if they should never have overlapped.
If the player changes area touching a gate when he is in area 0 or in area 2 (leftmost and rightmost), he will never stop in area 1 (the central one).
It seems that Godot takes some frames to update the position of colliders used to detect overlaps if they are moved this way.

Expected results:
The player changes area, no collectable object is collected since the only object that can collect a collectable is in a different area.
The player changes area touching a gate, he will always end up in the adjacent area.

Minimal reproduction project:
KB2DUpdatePositionTest.zip
Read the documentation in test.gd for further details.

@reduz
Copy link
Member

reduz commented Jan 17, 2019

The collider positions are updated every physics frame after you move them, not at the same exact moment you move them. KinematicBody2D will keep finding them at the same place even if you move them until a physics frame passed.

The reason for this is that it's considerably more performant to do it this way (moving everything at once) in the physics engine.

@akien-mga
Copy link
Member

This should have been closed after the above comment, it's indeed behaving as expected.

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

3 participants