-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
Add one-way collision to tile-set/tile-map (2.1) #8558
Add one-way collision to tile-set/tile-map (2.1) #8558
Conversation
I will change this in 3.0 so owc works shape based instead of body based..
as well as making direction relative to transform
…On Apr 27, 2017 1:44 PM, "Pedro J. Estébanez" ***@***.***> wrote:
Now you can set *one_way_collision_direction*/*_max_depth* on a tile's
static bodies. During conversion to a TileSet it will be checked whether
all static bodies for a given tile have the same values for those. If
that's not met, a warning will be printed and the relevant tile will be
converted with one-way collision disabled (all zeroes for those properties).
At runtime multiple physics bodies will be created for TileMap's
quadrants as needed. That is, one physics body per quadrant per different
set of one-way collision parameters. I've optimized the code as much as
possible to recycle physics bodies so to avoid as much creation/freeing as
possible at runtime in case tiles are changed dynamically.
*This deserves some testing. I will be testing it heavily myself.*
Not sure what to do about *master*. @reduz <https://github.com/reduz>
said in 3.0 those properties would be probably added to the collision
shapes instead, so this implementation would be meaningless for it.
Closes #2585 <#2585> (but only
for *2.1*).
------------------------------
You can view, comment on, or merge this pull request online at:
#8558
Commit Summary
- Add one-way collision to tile-set/tile-map
File Changes
- *M* editor/plugins/tile_set_editor_plugin.cpp
<https://github.com/godotengine/godot/pull/8558/files#diff-0> (20)
- *M* scene/2d/tile_map.cpp
<https://github.com/godotengine/godot/pull/8558/files#diff-1> (113)
- *M* scene/2d/tile_map.h
<https://github.com/godotengine/godot/pull/8558/files#diff-2> (8)
- *M* scene/resources/tile_set.cpp
<https://github.com/godotengine/godot/pull/8558/files#diff-3> (34)
- *M* scene/resources/tile_set.h
<https://github.com/godotengine/godot/pull/8558/files#diff-4> (8)
Patch Links:
- https://github.com/godotengine/godot/pull/8558.patch
- https://github.com/godotengine/godot/pull/8558.diff
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#8558>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AF-Z27G_OQUE9Bd0QLdyPxtAAAXH5w6Eks5r0H-SgaJpZM4NKGjy>
.
|
31e42c6
to
7b5b63f
Compare
Fixed compilation error (I was using Clang also seems to like it; only GCC complains, but I can confirm that such allowance is an extension. Just telling this in case someone is curious. |
7b5b63f
to
74d2e12
Compare
In my tests this is working fine. It may be a good time for merging so "early adopters" can start testing it easily. |
@RandomShaper I found that the converted tilesets may become invalid if no Here's a simple solution for that: struct Data {
String name;
Ref<Texture> texture;
Vector2 offset;
Vector2 shape_offset;
Rect2i region;
Vector<Ref<Shape2D> > shapes;
Vector2 one_way_collision_direction;
float one_way_collision_max_depth;
Vector2 occluder_offset;
Ref<OccluderPolygon2D> occluder;
Vector2 navigation_polygon_offset;
Ref<NavigationPolygon> navigation_polygon;
Ref<CanvasItemMaterial> material;
Color modulate;
// Default modulate for back-compat
explicit Data()
: one_way_collision_max_depth(0.0f)
, modulate(1, 1, 1) {}
}; |
@akien-mga I've merged this PR into my own game and it works pretty great so far, and the only issue I've met is the converting operation with its solution posted above, you may considering merge it so developers will be able to use this great feature :D |
@pixelpicosean Thanks for the feedback, for such changes it's always best to have Godot users testing the PR before it's merged and report back. Will wait for @RandomShaper's answer regarding the problem you found and merge once it's addressed. |
@pixelpicosean, thank you for having tried it out and reporting your experience! I'm really happy to know you find it useful. I'll add the missing initializer and push. |
74d2e12
to
417b6c5
Compare
Pushed! By the way, I'm not sure if the way clang-format is formatting initializer lists is too convenient. As they aren't extensively used throughout Godot, maybe it could be changed to split them vertically. @akien-mga, what do you think? |
417b6c5
to
2018db0
Compare
Now you can set one_way_collision_direction/_max_depth on a tile's static bodies. During conversion to a
TileSet
it will be checked whether all static bodies for a given tile have the same values for those. If that's not met, a warning will be printed and the relevant tile will be converted with one-way collision disabled (all zeroes for those properties).At runtime multiple physics bodies will be created for
TileMap
's quadrants as needed. That is, one physics body per quadrant per different set of one-way collision parameters. I've optimized the code as much as possible to recycle physics bodies so to avoid as much creation/freeing as possible at runtime in case tiles are changed dynamically.This deserves some testing. I will be testing it heavily myself.
Not sure what to do about master. @reduz said in 3.0 those properties would be probably added to the collision shapes instead, so this implementation would be meaningless for it.
Closes #2585 (but only for 2.1).