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

[Bullet] Rigid Bodies "floating" if CollisionShape is a Created Convex Collision Sibling #55503

Open
Tracked by #45022
Nekuromu opened this issue Dec 1, 2021 · 4 comments

Comments

@Nekuromu
Copy link

Nekuromu commented Dec 1, 2021

Godot version

3.4

System information

Windows 10

Issue description

Besides the peculiarities already on scaling physics bodies correctly without causing collision issues. I seem to have stumbled upon something.

If you use Create Single, Simplified, or Multiple Convex Collision Siblings versus a basic collision shape; The meshes will float when touching other rigid bodies if they have had their Collision Shape made this way.

Here are some cubes using the above methods of CollisionShape creation.
case_of_the_floaties

Then here are some using basic cube shapes on the right, compared to the same convex collision stack on the left.
image

Steps to reproduce

Upon running or opening and running my provided minimal reproduction project, you'll see we have 8 cubes in 4 colored groups of 2. (Example gif of what you'll observe below)

ConvexPolyIssue

Each color representing a "team" or "group" based on what collision shape method they use.

  • Group Red is using a CollisionShape(BoxShape) and work as intended and do not "float" on other bodies
  • Group Blue is using a CollisionShape(ConvexPoly) created with the "Create Single Convex Collision Sibling" button
  • Group Green is using a CollisionShape(ConvexPoly) created with the "Create Simplified Convex Collision Sibling" button
  • Group Yellow is using a CollisionShape(ConvexPoly) created with the "Create Multiple Convex Collision Siblings" button

All three of the latter do not work as intended when colliding or resting atop another RigidBody. This is the case even though each has an almost identical collision box scale visually in the editor. Visually from this issue, you could surmise that ConvexPolys have a larger scale during physics calculation than the editor shows.

Minimal reproduction project

ConvexCollisionIssue.zip

@pouleyKetchoupp pouleyKetchoupp changed the title Rigid Bodies "floating" if CollisionShape is a Created Convex Collision Sibling [Bullet] Rigid Bodies "floating" if CollisionShape is a Created Convex Collision Sibling Dec 1, 2021
@pouleyKetchoupp
Copy link
Contributor

Confirmed in 3.4 RC1 as a specific Bullet issue.
It doesn't happen anymore after switching to Godot Physics in Project Settings > Physics > 3D > Physics Engine.

Shapes in Bullet use a collision margin which is 0.04 by default. I'm not sure why it's affecting the collision distance for convex shapes but not box shapes.

As a workaround with Bullet, you can set the collision margin on the shape itself to something small like 0.001. It won't be as efficient for performance but it should work:
image

You can also use Godot Physics as a workaround. It has less features than Bullet on 3.4 and has its own specific issues, but it should still work ok for basic things.

@Nekuromu
Copy link
Author

Nekuromu commented Dec 1, 2021

@pouleyKetchoupp I have tried both, and they both seem to correct the issue... thanks for the workarounds until this is figured out! Definitely had me puzzled for a bit... glad to hear it wasn't just me and there really is something to it!

@Nekuromu
Copy link
Author

Nekuromu commented Dec 1, 2021

Just for anyone else who runs into this issue and plans to continue using Bullet, if you were to want to decrease all the margins at once with a function. Just make sure all RigidBodies are parented to one node called "Objects" and use something like this. Otherwise just switching to Godot Physics works fine.

=Edit=
If you do use this margin decrease method, be prepared for objects to more easily intersect and even pass through each other. The force required to do so is substantially less when you use the margin method.

extends Spatial

var main = null
var objects = null

func _ready():
	if ProjectSettings.get_setting("physics/3d/physics_engine") == "Bullet":
		print("Bullet Engine Detected, decreasing margins to fix floating RigidBodies")
		main = get_parent()
		objects = main.get_node("Objects").get_children()
		for object in objects:
			if object is RigidBody:
				var collision_shape = object.get_node("CollisionShape")
				if collision_shape.shape is ConvexPolygonShape:
					collision_shape.shape.margin = 0.005

@Nekuromu
Copy link
Author

Nekuromu commented Dec 22, 2021

Using the above methods aren't quite as helpful as previously thought. With further testing... the code I wrote has made clipping much worse. Very slow speed objects can zip right through each other, so this is no solution.

It seems the only current workaround that sort of works is to only use basic collision shapes even for complex meshes

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

4 participants