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

KinematicBody2D using move_and_collide makes other colliding KinematicBody2D move #21560

Closed
Tracked by #45334
samdze opened this issue Aug 29, 2018 · 8 comments
Closed
Tracked by #45334

Comments

@samdze
Copy link
Contributor

samdze commented Aug 29, 2018

Godot version:
Godot 3.0.6 and custom build 12290c1

OS/device including version:
Windows 10 64 bit

Issue description:
When a KinematicBody2D collides with another KinematicBody2D, they make each othe move if their movement is not parallel.
Reducing the safe margin mitigates the problem but doesn't completely solve it.

Here the object to the left performs move_and_collide(Vector2(15 * delta, 0)) and the one the right move_and_collide(Vector2(0, 0)) inside _physics_process. Safe margin is default 0.08.

Probably related to #18433

Minimal reproduction project:
move_and_collide_test.zip

@ghost
Copy link

ghost commented Sep 11, 2018

I can verify this as well, using Win10 64-bit with version 3.1 alpha c320d93.

Here is a 3.1 version of the above example project. (Seems compatible as far as I can tell.)
3.1 Move And Collide Test.zip

@eon-s
Copy link
Contributor

eon-s commented Sep 11, 2018

The project is using the default safe margin which is too high for this kind of interaction, all the bodies try to separate after move, making it move to the sides, reduce the safe margin to the minimum: 0.001.

@ghost
Copy link

ghost commented Sep 11, 2018

@eon-s That seems to solve it. That is quite a small margin value though. X)

@eon-s
Copy link
Contributor

eon-s commented Sep 11, 2018

On faster motions you can use higher margin (like on platformer demos), but if you want this kind of behavior, you must use a really low one.

@samdze
Copy link
Contributor Author

samdze commented Sep 11, 2018

Reducing the safe margin mitigates the problem but doesn't completely solve it.

Even setting it to 0.001 doesn't ensure the KinematicBody2D doesn't move.

If the current approach with collision detection doesn't allow to completely solve this issue, I'd like to choose whether to enable the "try to separate" behaviour when I move a body.

Could this be implemented in a convenient way?

@eon-s
Copy link
Contributor

eon-s commented Sep 11, 2018

It may still happens at very small motions, I do not know if there is a better option than test_move, check the results and decide if move or not to avoid pushing other objects.

@samdze
Copy link
Contributor Author

samdze commented Sep 12, 2018

That's not accurate enough, test_move only returns whether the movement would result in a collision or not, it doesn't provide any other informations.
The normal vector, the distance that is safe to travel before colliding with something, the colliding object and in general all the variables contained in KinematicCollision2D.

The only method I can think of is Physics2DDirectSpaceState's cast_motion, but it only provides the distance that it's safe to travel and the distance that would trigger a collision, this is not enough.

@Calinou
Copy link
Member

Calinou commented Sep 1, 2021

This is likely resolved in the physics nodes reorganization for 4.0, closing.

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