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

2D collision happens and is resolved, but helper methods are not updated. #15048

Closed
mythicsmt opened this issue Dec 25, 2017 · 7 comments
Closed

Comments

@mythicsmt
Copy link

Godot version: 2.1.4.stable
OS/device including version: Windows 10

Issue description:
Collisions between KinematicBody2D and StaticBody2D don't consistently set is_colliding, get_collision_pos, get_collider_metadata, etc when there is indeed a collision.

It seems if there is no difference between where the KinematicBody2D was before versus after the collision, it pretends the collision never happened. Very specific numbers seem to be required to encounter this, but it is easily reproducible.

Steps to reproduce:
Run attached project. Observe that is_colliding() never returns true even though a collision does indeed happen (and is resolved).

Expected: When collision happens, is_colliding should return true immediately after the move that triggered the collision. Also, get_collision_pos, get_collider_metadata, etc should also return collision related values.

Actual: is_colliding is false, get_collision_pos returns (0, 0), get_collider is null, get_collider_metadata is 0.

Minimal reproduction project:
CollisionBug.zip

@eon-s
Copy link
Contributor

eon-s commented Dec 26, 2017

The body margin is preventing the collision at that speed, if you reduce the margin (to 0.01 or smaller) the collision (overlap) happens correctly.

@mythicsmt
Copy link
Author

mythicsmt commented Dec 26, 2017

@eon-s There are several changes you can make to prevent this very specific scenario, but it seems to be a flaw with the overall engine that it would allow this situation at all.

If the engine is capable of recognizing the collision enough to stop the object from moving farther, should it not also be capable of setting all the collision related helper methods regardless of the margin/other parameters?

PS: I appreciate the margin change recommendation as a way to bypass the issue as a temporary fix, just making sure you weren't excusing the situation because you CAN get around it.

@eon-s
Copy link
Contributor

eon-s commented Dec 26, 2017

Is not a workaround (or excuse), is the proper set up.

This is what happens:

kbmargin

With safe margin bigger than the speed, the body is stuck without reaching the other body.
Can be seen if you zoom in the contact, there is a small separation.

kbmargin

I think the default margin is the issue, is too big and this problem arises in particular for people working with low resolution games (with a more noticeable effect of the margin push).
This default configuration affects 3 too (was reduced only on the spatial version of the KB).

@mythicsmt
Copy link
Author

@eon-s

So, there is a collision with the margin on the KB with the SB which halts the KB's movement, but doesn't actually trigger any other collision related code because the KB without the margin didn't actually overlap the SB at any point? This still, to me, sounds like a flaw with the engine to allow this.

Doesn't that mean any KB that slows down as it approaches an object could potentially hit the object at a speed lower than the margin value, therefore not triggering the collision as the developer would expect even with the minimum margin value?

So instead of just lowering the margin to lower the chance of failure, my better choice would be to always keep my margin lower than my speed and if my speed drops below the minimum margin value, to immediately stop my object and set the speed to 0. Sounds kind of hacky.

@Calinou
Copy link
Member

Calinou commented May 2, 2020

Can anyone still reproduce this on 3.2.1 or the master branch?

@eon-s
Copy link
Contributor

eon-s commented May 3, 2020

For some reason it happens now with very low safe margins (<0.005) on a converted OP example, default margin and up is fine, so no, I cannot reproduce the original issue.

collisionbug32.zip

@Calinou
Copy link
Member

Calinou commented May 3, 2020

Thanks for replying 🙂 I'll close this as resolved then.

@Calinou Calinou closed this as completed May 3, 2020
@Calinou Calinou added this to the 3.2 milestone May 3, 2020
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

4 participants