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

SoftBody shoots from point zero [GLES2] #41390

Open
Tracked by #45333
DrMoriarty opened this issue Aug 20, 2020 · 6 comments
Open
Tracked by #45333

SoftBody shoots from point zero [GLES2] #41390

DrMoriarty opened this issue Aug 20, 2020 · 6 comments

Comments

@DrMoriarty
Copy link
Contributor

Godot version:

Godot 3.2.3.rc (a6ef6b1)

OS/device including version:

MacOSX 10.15.5 (19F101)

Issue description:

I have several instances of scene with SoftBody inside. When scene starts SoftBodies jumps from 0,0,0 point so they have huge inertia in this direction and dangle around several frames.

Снимок экрана 2020-08-20 в 10 40 59

The screenshot shows flags from blue boat and from another one boat which is in left side out the screen.

The video of first few seconds of this scene:

Запись экрана 2020-08-20 в 10.39.10.zip

Steps to reproduce:

Make the scene with SoftBodies which are placed not in zero point. Run project on GLES2.

Minimal reproduction project:

@DrMoriarty
Copy link
Contributor Author

DrMoriarty commented Aug 20, 2020

Related: #35373
I think that in GLES2 SoftBody calculated on CPU and in GLES3 on GPU (with much more interesting behaviour #41391 )

Both bugs makes SoftBody completely unusable :-(

@DrMoriarty
Copy link
Contributor Author

If I change physics engine from Bullet to GodotPhysics, then SoftBody disappears after few frames. It doesn't dangle around like with Bullet just disappears.

@DrMoriarty
Copy link
Contributor Author

I noticed that NOTIFICATION_TRANSFORM_CHANGED for SoftBody called twice. The first one with real coordinates of object in 3d scene. On the second time the global transform of object is zero. So bullet soft body sets coordinates to 0,0,0 and on next frame it shoots.

@DrMoriarty
Copy link
Contributor Author

DrMoriarty commented Aug 20, 2020

I fixed this issue with quick and dirty hack:

diff --git a/scene/3d/soft_body.cpp b/scene/3d/soft_body.cpp
index 435bef7247..f56cb83ef1 100644
--- a/scene/3d/soft_body.cpp
+++ b/scene/3d/soft_body.cpp
@@ -268,6 +268,7 @@ void SoftBody::_notification(int p_what) {
 			RID space = get_world()->get_space();
 			PhysicsServer::get_singleton()->soft_body_set_space(physics_rid, space);
 			prepare_physics_server();
+			transform_inited = false;
 		} break;
 		case NOTIFICATION_READY: {
 			if (!parent_collision_ignore.is_empty())
@@ -280,25 +281,25 @@ void SoftBody::_notification(int p_what) {
 				_reset_points_offsets();
 				return;
 			}
-
-			PhysicsServer::get_singleton()->soft_body_set_transform(physics_rid, get_global_transform());
-
-			set_notify_transform(false);
-			// Required to be top level with Transform at center of world in order to modify VisualServer only to support custom Transform
-			set_as_toplevel(true);
-			set_transform(Transform());
-			set_notify_transform(true);
+			if(!transform_inited) {
+				PhysicsServer::get_singleton()->soft_body_set_transform(physics_rid, get_global_transform());
+
+				set_notify_transform(false);
+				// Required to be top level with Transform at center of world in order to modify VisualServer only to support custom Transform
+				set_as_toplevel(true);
+				set_transform(Transform());
+				set_notify_transform(true);
+				transform_inited = true;
+			}
 
 		} break;
 		case NOTIFICATION_VISIBILITY_CHANGED: {
 
 			_update_pickable();
-
 		} break;
 		case NOTIFICATION_EXIT_WORLD: {
 
 			PhysicsServer::get_singleton()->soft_body_set_space(physics_rid, RID());
-
 		} break;
 	}
 
diff --git a/scene/3d/soft_body.h b/scene/3d/soft_body.h
index 800db12594..68492a5472 100644
--- a/scene/3d/soft_body.h
+++ b/scene/3d/soft_body.h
@@ -96,6 +96,7 @@ private:
 
 	bool capture_input_on_drag;
 	bool ray_pickable;
+	bool transform_inited;
 
 	void _update_pickable();
 

I will not make a PR for that because the good solution should fix the caller who translates the soft body to zero point.

@akien-mga
Copy link
Member

Could you upload a minimal reproduction project to make it easier to debug?

@akien-mga
Copy link
Member

If I change physics engine from Bullet to GodotPhysics, then SoftBody disappears after few frames. It doesn't dangle around like with Bullet just disappears.

GodotPhysics doesn't support SoftBody in the 3.x branch yet.

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