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

One-way collision direction for tiles #7483

Open
pjhanzlik opened this issue Aug 11, 2023 · 5 comments
Open

One-way collision direction for tiles #7483

pjhanzlik opened this issue Aug 11, 2023 · 5 comments

Comments

@pjhanzlik
Copy link

Describe the project you are working on

Recreating World 1-1 from Super Mario Bros.

Describe the problem or limitation you are having in your project

Hidden blocks in Mario appear only when hit from below, but one way tile collision in Godot is implemented only from above. Furthermore, it would be nice to define a one way collision polygon on every Mario block keyed to the player, so that I know when Mario "bumps" a block to interact with it.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

When a tile collision polygon is specified as one-way there should be a rotation (or orientation) property which changes the direction the one-way collision occurs.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

I don't know how it would work from a physics engine perspective (I hope it is as easy as rotating a collision polygon that has been specified as one-way), but from a UI perspective:

Add a one-way orientation property

When you create a tile collision polygon in Godot 4.1.1 you can specify the properties one_way: bool = false and one_way_margin: float = 1.0. Add one_way_orientation: float = 0.0 to the properties list which allow users to specify a number between -360 and 360, just like the rotation for normal collision shapes. Unlike normal rotation, orientation would only affect the direction a one-way collision happens from.

Showing Collision Polygon Orientation in editor

Godot 4.1.1 indicates one-way collision is active on a polygon by overlaying pixel arrows pointing downward in the tile atlas view. This overlay can be reused to indicate the current orientation of a one-way collision by simply rotating them as well. The arrow overlay should also be visible from the tile collision polygon editor so that users can easily see them change when they change one-way collision orientation.

  • 360, 0, and -360: arrows pointing down, one-way collision from above (current 4.1 behavior)
  • 180 and -180: arrows pointing up, one-way collision from below (Mario Hidden Block behavior)
  • 270 and -90: arrows pointing right, one-way collision from the left (useful for one-way gates)

If this enhancement will not be used often, can it be worked around with a few lines of script?

Scene tiles are a good workaround, especially if all you want is a rotated one-way collision. That said, when I tried to create four Mario worlds in one TileMap the Godot 4.1.1 editor corrupted the scene I was working in. I imagine there was some weird interaction with the scene tiles I was using, but sadly didn't do much debugging when I could.

ShapeCast2D can simulate one-way collisions from the collider's perspective. The ShapeCast2D has to be adjusted per collider, but can be created using a script on another CollisionShape2D. Just have the CollisionShape2D generate a ShapeCast2D in a direction. The shape of the shape cast should be considered similar to the one_way_margin property, in that you need to test different shapes to get the type of one-way collision you want.

Overlapping a rotated TileMap works for creating lots of one-way collisions in one direction, though setup is confusing and fragile (terrains have to be setup according to orientation, tiles probably have to be flipped, etc.). I really don't recommend this approach unless all you want is one-way collisions from a particular direction.

Is there a reason why this should be core and not an add-on in the asset library?

Personally, I really would like tile collision polygons to be on par with CollisionShape2D. It feels weird to me that I can make objects intractable from only certain directions, but I can't do that with tiles because there is no way to "rotate" the collision polygon in the tile editor.

Having to add a ShapeCast2D to every collider to get this feature also feels kind of odd. Not really because

@F483
Copy link

F483 commented Jun 3, 2024

Bump, several user requests to be able to change the one way direction.

https://forum.godotengine.org/t/how-to-apply-one-way-collision-to-a-tilemap-in-godot-4/1319/8

@AThousandShips

This comment was marked as resolved.

@F483
Copy link

F483 commented Jun 3, 2024

@F483 Please don't bump without contributing significant new information. Use the 👍 reaction button on the first post instead.

I would say cross linking issues is significant information, I have always found it helpful when managing projects.

@AThousandShips
Copy link
Member

AThousandShips commented Jun 3, 2024

Then mentioning it directly would be the way to go, my bad, you literally said "bump" 😆 But it still doesn't add much information IMO

@neomoth

This comment was marked as off-topic.

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

5 participants