Implement 'body_is_shape_set_as_one_way_collision' in PhysicsServer2D #12824
Handagotes
started this conversation in
2D
Replies: 1 comment
-
Today I tried to implement this feature in forked godot repo and it worked great! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello!
One-way property of shapes in PhysicsServer2D is set-only for some reason. I suggest to implement a getter method 'body_is_shape_set_as_one_way_collision'.
Describe the project you are working on
2D platformer with heavy use of tile maps.
Describe the problem or limitation you are having in your project
I want to implement a feature that allows players to drop down through semisolid objects.
To do this, I need a reliable way to determine if the player is standing on semisolid object (with one-way collision).
I use Area2D and 'body_shape_entered' signal to do this.
For CollisionObject2D nodes this is trivial, because they have convenient 'is_shape_owner_one_way_collision_enabled' method.
Unfortunately, there is no easy way to do this for TileMapLayer, especially after GH-102662 being merged.
In 4.4 I used this code:
In 4.5 I will not be able to use 'get_coords_for_body_rid' method because it will return physics quadrant coordinates instead of tile coordinates. Explanation
Describe the feature / enhancement and how it helps to overcome the problem or limitation
PhysicsServer2D has method 'body_set_shape_as_one_way_collision', but doesn't have a getter version of this method.
Method 'is_shape_set_as_one_way_collision' in PhysicsServer2D needs to be implemented. It will make one-way shape detection very easy.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
First of all, 'body_is_shape_set_as_one_way_collision' method must be added to PhysicsServer2D and in inherited classes.
This method must be exposed to engine users as well.
After this, one-way shape detection with Area2D becomes very trivial:
If this enhancement will not be used often, can it be worked around with a few lines of script?
Workaround would require using RayCast2D with or instead of Area2D.
This will allow me to write something like this:
I see this workaround as a crutch - the player can stand on different shapes simultaneously, which can result in false semisolid detection. To counter this, I would need more than one RayCast2D.
This idea gets ugly pretty fast when I try to consider all in-game situations.
Is there a reason why this should be core and not an add-on in the asset library?
Addons cannot expose internal engine API as far as I know.
Maybe it can be implemented using GDNative plugin, but I'm not sure.
In any case, using separate plugin to expose single getter for property is ugly.
I just can't think of any good reason why one-way property for shapes must be set-only in PhysicsServer2D.
Beta Was this translation helpful? Give feedback.
All reactions