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

move_and_collide returns inconsistent values #59139

Closed
alostgrue opened this issue Mar 14, 2022 · 4 comments · Fixed by #59438
Closed

move_and_collide returns inconsistent values #59139

alostgrue opened this issue Mar 14, 2022 · 4 comments · Fixed by #59438

Comments

@alostgrue
Copy link

Godot version

3.4.stable

System information

Windows 10, GLES3

Issue description

I'm using move_and_collide with test_only = true to check if the player is on the ground. After updating to 3.4, it sometimes detects a collision when the player is next to a collision shape and moving straight down (tested with solid tiles and CollisionShape2D with different shapes).

Steps to reproduce

Run minimal example and jump while standing directly next to the platforms. The behaviour is different for each numbered location:

1 - always sticks
2 - mostly works correctly (sometimes sticks for a brief moment when colliding from above at an angle, but this is somewhat difficult to trigger)
3 - sticks only if direction towards platform is held
4 - sticks until landing if direction towards platform is tapped

Minimal reproduction project

collision_test.zip

@Calinou
Copy link
Member

Calinou commented Mar 14, 2022

Can you test this on 3.4.3? This may have been fixed since 3.4 was released.

@alostgrue
Copy link
Author

Can you test this on 3.4.3? This may have been fixed since 3.4 was released.

Checked in 3.4.3 - no change.

@Hiiamwilliam
Copy link

I think the issue may not be on move_and_collide.

I replaced the TileMap with a StaticBody2D with a few SegmentShape2D to mimic the collisions of the TileMap. In this new situation, the player behaves as expected, which means the inconsistency problem could be on TileMap-generated CollisionShapes. I could also be totally wrong - I don't have deep knowledge on Godot physics.


Now, this may be off-topic, but I think there is a misunderstanding on what should be expected behavior. OP said that point 2 mostly works correctly, but I believe the only point that shows correct behavior is 1. According to the docs on move_and_collide:

Returns a [KinematicCollision2D], which contains information about the collision when stopped, or when touching another body along the motion.

Since the Player's body touches the sides of the platform, it should show collision information, which only happens consistently on point 1. To me, point 2 is actually the most borked, since it never seems to touch the Player. Maybe there's some weird floating point error.

Also, note: move_and_collide requires its "velocity" to be multiplied by delta (the one from physics_process). However, mutiplying by delta doesn't help with this issue.

Finally: if you wish to test only for collisions along a specific path, and not care about unrelated contacts, you should try the test_move method:

Returns true if a collision would stop the body from moving along the whole path.

@fabriceci
Copy link
Contributor

After the PR linked:

after pr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants