-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
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
Unable to set margin on CollisionPolygon resulting in noticeable gaps when using Bullet engine #45718
Comments
Author of the workaround here. Are you sure this code doesn't work?: func _ready() -> void:
fix_collision_polygons($"/root/Game/World") # Your nodes to fix here
func fix_collision_polygons(parent: Node) -> void:
for child in parent.get_children():
if parent is PhysicsBody and child is CollisionPolygon and not child.disabled:
var body := (parent as CollisionObject).get_rid()
for i in PhysicsServer.body_get_shape_count(body):
var shape := PhysicsServer.body_get_shape(body, i)
if PhysicsServer.shape_get_type(shape) == PhysicsServer.SHAPE_CONVEX_POLYGON:
var new_convex_polygon_shape := ConvexPolygonShape.new()
new_convex_polygon_shape.margin = 0
new_convex_polygon_shape.set_points(PhysicsServer.shape_get_data(shape))
var new_collision_shape := CollisionShape.new()
new_collision_shape.shape = new_convex_polygon_shape
new_collision_shape.transform = child.transform
parent.add_child(new_collision_shape)
child.free()
else:
fix_collision_polygons(child) |
I must have made a typo somewhere when trying it last time, because I can't break it this time! Above example and the one from the original post seems to work |
Glad we could get it to work. I do a lot of CSG / collision workarounds like this for my projects so let me know if you need any more help. |
Ahhh OK, this issue can probably be closed then and just added as a note to #27427 then. I didn't realise Thanks for the fix too! I ended up scaling everything up in the project I ran into it with, which has actually helped fix some lighting issues too, but I'll definitely keep this solution bookmarked for future use 😃 |
I'm sorry, I take it back entirely - adding a |
Godot version:
v3.2.3.stable.official
OS/device including version:
Ubuntu 18.04
Issue description:
When a
RigidBody
with aCollisionShape
collides with aStaticBody
that contains aCollisionPolygon
, a noticeable gap can be seen which seems to be the default margin that is applied. Unlike other collision objects, it's not possible to set the margin of theCollisionPolygon
though.A potential work around was mentioned in This Similar Issue, but I was unable to get it to work.
An example of the gap can be seen in this screenshot:
Minimal reproduction project:
https://github.com/RobTheFiveNine/godot-collision-polygon-margin-example
The text was updated successfully, but these errors were encountered: