Godot: Poor optimizations in the physics engine

Created on 31 Jan 2017  ·  17Comments  ·  Source: godotengine/godot

Operating system or device - Godot version:
Fedora 25 (Linux)

Issue description:
Collision shapes on even simple meshes can cause serious performance hits on the smallest collisions. Here is a video of a car of mine colliding with my roads, which collision shape seems to be that of a cube, at the least a very simple mesh

It is common also for after the performance hit for the mesh to seemingly teleport elsewhere and collide right though objects.
output

Steps to reproduce:
I can create a simple scene (using non default objects like the cube), say a car and a much simpler map, and I will get similar behavior

bug discussion physics

Most helpful comment

yeah, there is a bug in the convex polygon shape I never got to solve.
Using basic shapes instead solves the problem.
If all goes well, we will be merging bullet as back-end soon

On Sun, Aug 20, 2017 at 7:05 PM, Espen Breivik notifications@github.com
wrote:

Running latest code (35d5724
https://github.com/godotengine/godot/commit/35d57245193d37ac8cba5e2c8df7957f0239b19d)
on Windows 10.
Notice the extreme lag spikes when colliding with other objects. There is
also a small heightened edge on the roads themselves that causes some
intererence.

If anyone's interested-here's the project:
Alpha-1-Test.zip
https://github.com/godotengine/godot/files/1237387/Alpha-1-Test.zip

[image: racing-lag]
https://user-images.githubusercontent.com/1427902/29498822-afef1e66-8603-11e7-92f6-7f775346acd9.gif


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/godotengine/godot/issues/7690#issuecomment-323615082,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AF-Z27mDq447KzkJCt0KFHW9221IszQDks5saK2-gaJpZM4LzB_T
.

All 17 comments

Personally I understand why Godot has it's own physics engine; but I think the best long term solution to issues like this would be to eventually migrate to Bullet physics, or allow it as an option.

So can you provide a minimal example?

https://notabug.org/bkeys/DMUX/archive/master.tar.gz
In JoinGameButton.gd you can swap out which scene it loads with the castle scene, the castle scene has the same (all be it less fatal) issue.

On your other issue about meshes, I saw an image of your truck. This image shows a over complicated collision shape.
I assume it was generated directly from the truck mesh.
I suggest to modelize a simple shape in order to generate the collision shape truck, then you can delete this mesh from the scene and keep a clean collision shape.
Maybe it's not the main solution but this is an easy optimization to do.

Just for reference, I just added collision meshes to my terrain plugin using the trimesh collision helper, and it worked like a charm: https://www.youtube.com/watch?v=531szCVfZPw
I didn't do a bunnymark benchmark on this but Cubes vs Mesh has decent performance. Maybe performance is only slow with Mesh vs Mesh?

I started testing Godot 3.0 alpha1, and I can confirm that mesh-to-mesh collisions on even simple shapes gives a noticable lag. I used some of the assets from Kenney which are fairly simple, and added

  • Import an OBJ file from a Kenney pack and create a new scene for the obj-file
  • Select the mesh and use the function Create Convex Static Body
  • Change type of StaticBody to RigidBody
  • Reorganize hierarchy so that the root node in the object scene is the RigidBody, and the Mesh + Collisionshape are children of the physics node
  • When colliding with other objects of this type - there is a noticable visual jitter / frame drop

image

image

Curious about the reorganizing hierarchy step. Does the jitter happen if the hierarchy is left as-is? Or if you have a Spatial as the root?

I never reproduced this issue with primitive collision shapes (boxes, capsules...).

I couldn't find a good way organizing it so that the mesh followed the body in this case. I had some troubles with the scene since it was inhereted and the mesh would be duplicated. Not completely sure why the generation function generates children for a mesh - seems kinda useless to me?

Just built the latest version from git 30 mins ago and it was worse - may have to do with some a lot of messages with WARNING: AudioDriverRtAudio::callback: RtAudio output underflow! At: drivers\rtaudio\audio_driver_rtaudio.cpp:57 several times per second.

Running latest code (35d57245193d37ac8cba5e2c8df7957f0239b19d) on Windows 10.
Notice the extreme lag spikes when colliding with other objects. There is also a small heightened edge on the roads themselves that causes some intererence.

If anyone's interested-here's the project:
Alpha-1-Test.zip

racing-lag

yeah, there is a bug in the convex polygon shape I never got to solve.
Using basic shapes instead solves the problem.
If all goes well, we will be merging bullet as back-end soon

On Sun, Aug 20, 2017 at 7:05 PM, Espen Breivik notifications@github.com
wrote:

Running latest code (35d5724
https://github.com/godotengine/godot/commit/35d57245193d37ac8cba5e2c8df7957f0239b19d)
on Windows 10.
Notice the extreme lag spikes when colliding with other objects. There is
also a small heightened edge on the roads themselves that causes some
intererence.

If anyone's interested-here's the project:
Alpha-1-Test.zip
https://github.com/godotengine/godot/files/1237387/Alpha-1-Test.zip

[image: racing-lag]
https://user-images.githubusercontent.com/1427902/29498822-afef1e66-8603-11e7-92f6-7f775346acd9.gif


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/godotengine/godot/issues/7690#issuecomment-323615082,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AF-Z27mDq447KzkJCt0KFHW9221IszQDks5saK2-gaJpZM4LzB_T
.

@reduz thanks for the reply! I also used this scene when testing the version 14c11fb97a1916759915e0e706d25a440b4f21da from the godot fork created by @AndreaCatania and switched to the Bullet-engine, but it had worse issues with collision shapes, and I experienced other periodic lags. As an example - the pylons just tunneled through the road at the beginning using the Bullet engine implementation. (It also didn't handle the huge static collision shape which is a simple scaled plate - but I now the old Godot saying - you shouldn't scale collision shapes).

So the best build I have tested for now is the "official" Alpha1. It might be a crap scene, and I have very limited experience with 3D in general - but consider this a "naive" approach to creating a 3D scene with pre-exiting assets 😄

Also, personally I have no idea how I would start constructing a simple collision shape for pre-existing meshes - it seems like a near impossible task in the editor without any tooling for assistance (like you have in 2D editors). I would probably need to do this in a 3D program?

@DjPale In this case I created a simple shape in Wings 3D software, who is very easy to learn and to use. Then I use Godot mesh menu to create the collision shape from this mesh.

@DjPale I've fixed the problem with scaled objects. Now The ground is working correctly.
The freezing that you mention with Bullet physics engine in reality are not a "Freeze", but is a problem in your GDscript. You are controlling the rotation of a rigid body in a wrong way. To know more about it and how to fix this problem check my answer on here: https://github.com/godotengine/godot/pull/10013#issuecomment-324920020

@AndreaCatania re-compiled your branch, works like a charm! I also used set_angular_velocity in _integrate_forces and there are no lag anymore when using the Bullet engine 👍

According to previous comment and the fact that bullet is now merged I think this one can be closed :)

Was this page helpful?
0 / 5 - 0 ratings