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

Godot: Inconsistent behaviour for the one-way collision margin parameter of CollisionPolygon2D #335

Open
Hymenium opened this issue Jan 8, 2025 · 3 comments
Labels
bug Something isn't working

Comments

@Hymenium
Copy link

Hymenium commented Jan 8, 2025

Describe the bug - inconsistent behaviour with Godot 2D engine

In Godot, a CollisionPolygon2D object has a one-way collision margin parameter (https://docs.godotengine.org/en/stable/classes/class_collisionpolygon2d.html#class-collisionpolygon2d-property-one-way-collision-margin), defaulting to one pixel.

This parameter seems to change the size of the polygon in the direction of the one-way collision, and the result of this parameter is not identical in Rapier2D. This can be demonstrated if you translate the position of a CharacterBody2D over the margin. In the Godot engine, it will enter the polygon, but the position must be translated further in Rapier2D to get the same results.

This behaviour may be preferable in some scenarios (higher velocities) but is inconsistent with the default engine and the parameter value.

To Reproduce

Translate the position of a CharacterBody2D by the size of the margin into the polygon in the direction of the one-way collision and apply some velocity in the same direction. Using the Godot engine, the body will enter the polygon, but the position must be translated further initially to get the same results using Rapier2D. For example, three pixels for a one pixel margin.

Expected behaviour

I would expect consistent behaviour across engines if the parameter is handled, or clear advice otherwise. It would be very helpful to see in the project settings how the parameters are used by Rapier2D, similar to the Godot parameters that have tooltips and linked documentation.

Environment:

  • OS: Windows (probably not important)
  • Version: latest main v0.8.10 (build# 1005)
  • Godot Version: v4.3 (and v4.4dev7)
  • Type: simd single 2d parallel

Example project(zip)

one_way_test.zip

Using a drop through a one-way platform to demonstrate.

Inputs: Left and right arrow keys to move the CharacterBody2D horizontally, down key to drop one pixel and up key to drop three.

Set-up: CharacterBody2D has a rect collider and the template script with the drops added. Both the static body and tile set have polygon colliders with one-way collisions, pointing down, and default one way collision margins of 1 pixel. All shapes are in the same collision layer.

Result: If Godot 2D engine is used then gravity and the up or down keys allow the CharacterBody2D to pass through, but with Rapier2D only the up key (drop 3 pixels) will allow the body to pass through.

@Hymenium Hymenium added the bug Something isn't working label Jan 8, 2025
@Hymenium
Copy link
Author

Hymenium commented Jan 8, 2025

Sorry I didn't check the labels

@Ughuuu
Copy link
Contributor

Ughuuu commented Jan 9, 2025

Np, I think it's automatically set as bug the label. That' the default. I can change it if needed.

@Hymenium
Copy link
Author

Hymenium commented Jan 9, 2025

Thanks, I wasn't sure if this was a bug exactly, but if this parameter is the same in Rapier2D then I guess it is.

I noticed that the one-way collision data is part of the parent class CollisionShape2D (https://docs.godotengine.org/en/stable/classes/class_collisionshape2d.html), so this behaviour may be more general than collisions involving rects and polygons. It seems to depend on the interpenetration in the initial translation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants