Bullet physics in Godot 4.
Asked Answered
G

41

0

Hello!

As a few people have figured it out the hard way, Godot 4 native physics is a little bit unstable in some situations. And there was even a petition πŸ™‚ regarding returning Bullet physics back into Godot4 which as I understand has been rejected by the developers.

If anybody is interested, after struggling for about 2 weeks I've finally made Godot3 Bullet module compile in Godot4. I had to insert a number of dummy methods to just make it compile as physics_server_3d.h has no information related to what all the virtual methods are supposed to do.

Also Godot developers did excellent job renaming literally almost every single method, every single property, and every single data type. It really doesn't add reliability in the process of porting even the code I made myself from v3 to v4 not talking about something I didn't ever look into πŸ™‚

As far as I understand, there are a few people interested in Bullet working in Godot4. The big problem is that servers/physics_server_3d.h has absolutely no documentation. And it is not clear what all numerous new methods are supposed to do. If you have any insights or willing to help, please check out the code: https://github.com/z80/ignition/tree/bullet/godot.

Please let me know.

Geniegenii answered 24/4, 2023 at 20:19 Comment(0)
G
0

Hello again!

I was analyzing the Godot4 physics code. There is one thing I cannot understand about RID_PtrOwner<> class. After object creation pointer is placed into RID_PtrOwner<> which in return gives them a RID (an integer). And each time when they need a pointer to the object (and it happens on every physics API call), they give RID_PtrOwner<> the rid and it in return gives back the original pointer they stored. Why not just keep the original pointer, why use a dedicated storage while holding a rid corresponding to the pointer id in the storage container? There must be some hidden logic here...

See the example below.

class GodotPhysics
{
RID_PtrOwner<Object> object_owner;

GodotPhysics::create_object()
{
    Object* obj = godotnew(Object);
    RID rid = object_owner.make_rid(obj);
    return rid;
}

Object * GodotPhysics::get_object( RID rid )
{
    Object * obj = object_owner.get_or_null( rid );
    return obj;
}
};
Geniegenii answered 25/4, 2023 at 17:55 Comment(0)
C
0

Geniegenii Maybe you'd better post such question in a discussion/proposal on Godot github repository, there is bigger chance a dev sees it an reply.

My guess is either it's some storage made for something no longer in use or, worth, a misunderstanding (which would be unbelievable at this level but who knows ?) about pointer and object, the author thinking the function will have to deal with a full instance of a class pass by value in functions/methods instead of a mere pointer as it is, in such case, it could makes senses to do that... I'm not even sure because the id will be use anyway to acquire the object itself.

This more looks like a useless indirection. Anyway, it's a good opportunity for discussions and challenge actual architecture.

Communion answered 26/4, 2023 at 9:14 Comment(0)
G
0

Communion Actually, after thinking for a while, I believe, I see the reason. This RID_PtrOwner<> with some stretch of imagination is somewhat similar to using std::weak_ptr<>. I.e. if the object has been deleted and removed from this RID_PtrOwner<> container, requesting object by its rid returns nullptr. And using a single container for multiple small objects somewhat makes sense as there is just a single memory usage for one RID_PtrOwner<>. In contrast, using std::weak_ptr<> per each pointer creates bigger overhead...

Geniegenii answered 26/4, 2023 at 23:27 Comment(0)
G
0

Ok, after a few more days and tons of bad language it actually works now!
See the video:

Geniegenii answered 28/4, 2023 at 5:12 Comment(0)
C
0

Geniegenii Great ! It would be nice to add some tests using the concave mesh issue discussed a while ago as well as your unstable joints issue.

By the way, regarding this issue, Unity also suffer from weird issues (looks like some force gain momentum with time then grow exponentially and makes everything explode in KSP), I think it would be much better to automatically "weld" parts together into a single collider mesh so the physics engine only have to deal with a single entity and not a bunch of parts stuck together with bad glue and duck tape. Especially regarding the gameplay added value for such poor model, IMHO, it doesn't add much but cost a lot of annoyance and performance issues.

Finally, do you have some compile editor ready to use ? It would be great (don't forget to tweak the version as well !)

Communion answered 28/4, 2023 at 7:6 Comment(0)
G
0

Communion Great ! It would be nice to add some tests using the concave mesh issue discussed a while ago as well as your unstable joints issue.

Yes, that's in the nearest TODO list.

Communion looks like some force gain momentum with time then grow exponentially and makes everything explode in KSP

That's side effect of using speed-based constraints and simulating bodies separately via Newton/Euler equations. Bullet actually has generalized coordinates-based Largrange equations to solve this issue perfectly. It's called Featherstone method. It's located in \godot\thirdparty\bullet\BulletDynamics\Featherstone. It's not yet supported by Godot though.

The poor man's today alternative is simulating all connected pieces as a single rigid body πŸ™‚

Communion Finally, do you have some compile editor ready to use ? It would be great (don't forget to tweak the version as well !)

Sure, here you go (the url leads to the game page, I couldn't come up with anything better to hosting it there):
.

For now version is the commit SHA256:

Geniegenii answered 29/4, 2023 at 2:22 Comment(0)
C
0

Geniegenii It could be interesting, if interface to both Bullet and new Godot native physics engine are the same or very compatible, to provide both implementations of Ignition so it could help comparing both and devs could also identify what they need to do to at least reach Bullet level engine.

For the download, why not use release on github directly ? I've never used it yet myself so I can't help.

Communion answered 29/4, 2023 at 10:32 Comment(0)
G
0

Communion why not use release on github directly ?

Ah, it's dumb as usual. I wasn't able to find "draft a new release" button. Github says "At the top of the page, click Draft a new release".
It turned out, it's not at the top, it's on the right πŸ™‚ Here is the github release download url godot.windows.editor.x86_64_7aca0f70.zip.

Geniegenii answered 30/4, 2023 at 1:31 Comment(0)
G
0

Ok, just tried it in the real game.

First, on positive side, when switched to Bullet, the physics doesn't blow up anymore! That's a win!

On the negative side
1) Even though concave mesh collision shape is created, I can see it with Debug/Visible Collision Shapes check box. But for some reason collisions don't happen. Bodies fly right through.
2) Even though joints are created, they don't work for now. Constructions just fall apart when pushed.

Geniegenii answered 30/4, 2023 at 1:59 Comment(0)
G
0

Ok, new update: godot.windows.editor.x86_64_b49f801f3.zip.
Fixes:

  • Joints work
  • Concave polygon shape works.
Geniegenii answered 30/4, 2023 at 6:44 Comment(0)
G
0

The return of bullet physics in Godot 4 is one of the biggest achievements along with the introduction of Vulcan. Is it possible to make a module for Godot? This will please many developers. Not everyone will want to install a separate build or compile it, a module will allow you to distribute your work throughout the community. In any case, I want to thank you. This gave hope to our studio to stay on Godot in the future, as we decided to switch to another engine due to physics.

Goldagoldarina answered 30/4, 2023 at 8:42 Comment(0)
G
0

Goldagoldarina

Goldagoldarina Is it possible to make a module for Godot? This will please many developers. Not everyone will want to install a separate build or compile it, a module will allow you to distribute your work throughout the community. In any case, I want to thank you.

Great idea, thank you! I know they've changed binary modules design process a lot but didn't look into it yet. I'll check what it takes to make a module out of Bullet physics server...

Geniegenii answered 30/4, 2023 at 17:13 Comment(0)
G
0

Goldagoldarina Bad news.

I've been trying to convert it to GDextenstion. I've checked out godot_cpp.git 4.0.2-stable tag which corresponds to 4.0.2-stable godot current version.

The obstacle I've encountered is G6DOFJointAxisFlag enum in Godot : : PhysicsServer3D and godot_cpp : : PhysicsServer3D do not correspond to each other. G6DOF_JOINT_FLAG_MAX is not defined in godot_cpp as well as a few other enums.

So, I guess having Bullet physics as a GDextension binary plugin is delayed... For now only the built-in version is available.

I've created an issue: https://github.com/godotengine/godot-cpp/issues/1104. Will see what happens...

If it matters, I've created a separate github repo for porting Bullet to GDextension.

Geniegenii answered 30/4, 2023 at 22:55 Comment(0)
G
0

Maybe then suggest a merge into the main repository? To include your work in the engine? The developers did not want to waste time implementing Bullet, but since a good person did everything for them, maybe they will take it as the basis of the engine?

I've added the suggestion to the discussions.
https://github.com/godotengine/godot-proposals/discussions/6687#discussioncomment-5602799

Goldagoldarina answered 1/5, 2023 at 7:55 Comment(0)
G
0

Goldagoldarina My personal favorite quote in the conversation is "By giving Godot users no other way, it's forcing evolution for the best, with some pain along the way."

I would just add "Or it makes Godot users switch to Unreal and give up Patreon support" πŸ™‚ Which is indeed evolution for the best in some sense πŸ™‚

Geniegenii answered 1/5, 2023 at 16:1 Comment(0)
P
0

Awesome, thanks for making the integration! I, for one, can't wait for an additional Physics library option other than Godot's Physics for 3D.

Also be sure to check Godot Jolt which is a GDExtension in progress for Jolt in Godot. It's almost fully working. So you also might get ideas from the code, if needed: https://github.com/godot-jolt/godot-jolt

Praetorian answered 1/5, 2023 at 17:15 Comment(0)
G
0

Praetorian Also be sure to check Godot Jolt which is a GDExtension in progress for Jolt in Godot. It's almost fully working. So you also might get ideas from the code, if needed: https://github.com/godot-jolt/godot-jolt

Yea, thanks for the hint! I'm aware of Godot-jolt. It's absolutely great!

In the case of making a GDextension out of Bullet it seems like it's a bug in the command "godot --dump-extension-api extension_api.json" which is supposed to generate all the API. Specifically for PhysicsServer3D it doesn't export several enums which are needed for Bullet to work. The devs have already assigned it a bug flag, see https://github.com/godotengine/godot-cpp/issues/1104.

@"alfredbaudisch"#p110287 oh but notice how I just said "with Bullet/Jolt" and not Godot's Physics itself 😬

Absolutely! IMHO it's much less of a pain to rely on something tested. Despite of all the arguments the devs' position 1) claim lack of contributors and at the same time 2) developing custom physics engine from scratch still does not line up in my head πŸ™‚

Geniegenii answered 1/5, 2023 at 17:33 Comment(0)
S
0

ive also found physics unreliable in godot 4. some collisions just dont get correctly detected.
is this because of godot physics? if so, is bullet physics so much better?

Spectroscope answered 1/5, 2023 at 17:39 Comment(0)
P
0

Spectroscope is this because of godot physics? if so, is bullet physics so much better?

Bullet is battle-proven, with many shipped titles.

GTAIV and Read Dead between them:

Bullet is an open-source 3D physics library produced by Erwin Coumans, featuring rigid and soft body physics, 3D collision detection and multiple 3D modelling/animation software plugins. The library has been incorporated into the Rockstar Advanced Game Engine, which has been used by Grand Theft Auto IV and Red Dead Redemption.

Praetorian answered 1/5, 2023 at 17:45 Comment(0)
G
0

Given the position of the developers, I see the only way to make a module from Bullet. We are waiting for the correction of the error that does not allow this. I hope they fix this at least soon. Until this happens, I beg the Z80 to support us with new versions with corrections and not give up this good cause. You are saving the community at this difficult time.

Goldagoldarina answered 2/5, 2023 at 4:24 Comment(0)
G
0

Hello everyone!
I've just fixed a bug in Bullet physics support for Godot4 and upgraded to the most recent 4.0.3-stable except two files viewport.h/viewport.cpp which in some of my projects make viewport texture to not work.

Please find the code snapshot and windows-64bit binaries here https://github.com/z80/ignition/releases/tag/commit_cd4f85694.

Geniegenii answered 13/6, 2023 at 1:3 Comment(0)
C
0

Geniegenii Hi appreciate you working on this, I've managed to pull out the Bullet Physics stuff from your repo into the latest builds for Godot for my own project however I noticed an odd issue with the implementation.

The capsule colliders seem to not be working correctly, They seem to apply an additional invisible barrier that doesn't seem to show in the debug collisions. It was pretty easy to get this to repeat I also built your instance of the engine just in case it was limited to just my version and it seems like the issue is present in both. I'm guessing this is something to do with margins since the collision debug seems to show the capsule scaled correctly etc.

Steps I did to see this issue:

  • Create a basic scene with some cubes that fall and can be pushed by a character body.
  • Create a basic character movement script to move left right back forwards.
  • Move around the scene and you will see that the cubes are pushed by an invisible force, attached to the capsule.
  • You can also see its limited to just capsules as by simply changing the collision shape to something else such as cylinder the issue is gone.
  • Swap to using Godot Physics, Issue is not present and collision applies normally and as expected with capsule collider.

Any ideas on how to solve this issue? Also is there any updates on moving this stuff to GDExtensions it seems like your bug report hasn't been updated in awhile?

Cockspur answered 17/9, 2023 at 19:4 Comment(0)
C
0

Cockspur I actually managed to fix this issue but posting the solution in case anyone else is attempting to use the implementation.

So there is two issues, In Godot 4 the default capsule orientation is upright rather than aligned along the Z axis. Since the implementation uses the code from Godot 3.5 the alignment is still aligned to the Z axis instead of upright. You can fix this in the bullet code so that instead of creating and returning a BtCapsuleShapeZ you return a BtCapsuleShape, This will fix the alignment issues and the strange invisible force.

Alongside this another issue encountered is that the capsule height is no longer aligned with the debug widgets heights and just the general capsule height as it seems like Godot 4 expects that to be the exact height. This causes an issue as bullet expects a half height(This is just knowledge from implementing bullet in a custom engine so could be slightly incorrect but seems to resolve this issue).

This will cause issues with capsules appearing like they are floating or just general strange height related issues. To solve this simply divide the height received in the CapsuleBulletShape::setup method by 2(You could do this earlier in the callstack but it seems like a sensible place to do it as it keeps it within the bullet module). This will give you the half height which is what bullet expects.

Good luck to anyone else using this!

Cockspur answered 17/9, 2023 at 20:36 Comment(0)
G
0

Cockspur
Sorry for the bug! And thank you so much for the detailed explanation of the fix! That's awesome! Is there any place I could pull the changes from? If not, I'll try to follow your instruction. Thank you again!

Geniegenii answered 23/9, 2023 at 19:39 Comment(0)
G
0

Cockspur
Ok, I've changed it from

btCapsuleShapeZ *ShapeBullet::create_shape_capsule(btScalar radius, btScalar height) {
return bulletnew(btCapsuleShapeZ(radius, height));
}

to

btCapsuleShape *ShapeBullet::create_shape_capsule(btScalar radius, btScalar height) {
// Bullet expects half height.
return bulletnew(btCapsuleShape(radius, height*0.5));
}

It seems like it does the job. Thank you again for the bug detection and how to fix instruction! That's open source in action!

The code with the fix applied: https://github.com/z80/ignition/tree/bullet_godot_4_1bf56109f6

Code snapshot and binaries for Windows: https://github.com/z80/ignition/releases/tag/bullet_godot_4_1bf56109f6

Geniegenii answered 24/9, 2023 at 20:3 Comment(0)
C
0

nice stuff.
Good to see there is another alternative to vanilla engine physics.(The other alternative is jolt3d)
No offense intended, but the physics3d in 4.0 is a piece of ****, especially performance and stability wish. A few convex shapes with like 50 vertices colliding each other will cause the physics time jumping from 16ms to 1000+

Cataplexy answered 25/9, 2023 at 7:32 Comment(0)
G
0

Upgraded Bullet physics support to Godot 4.1.2-stable.

Source code: https://github.com/z80/ignition/tree/godot_4.1.2_stable_960ccf8fe9

Windows binaries: https://github.com/z80/ignition/releases/tag/godot_4.1.2_stable_960ccf8fe9

Geniegenii answered 8/10, 2023 at 6:49 Comment(0)
S
0

The question, so far, is theoretical. If I want to use physics and AI in my project at the same time, do I have to compile the engine myself, including them there?

Salangia answered 8/10, 2023 at 14:2 Comment(0)
K
0

Salangia From what I understand If they are all GDExtension plugins that are provided in pre-compiled(linked library) form then in theory you shouldn't need to compile anything though you have to make sure the versions of each including godot itself match up.

If however one or more of the things you are looking to use takes the form of a module then it needs to be compiled into the godot engine itself far as I'm aware.

Katanga answered 8/10, 2023 at 15:10 Comment(0)
S
0

Katanga If however one or more of the things you are looking to use takes the form of a module then it needs to be compiled into the godot engine itself far as I'm aware.

Yeah, that's what I have a question about, since Jolt has an extension version, but the listed modules do not.

Salangia answered 8/10, 2023 at 15:29 Comment(0)
G
0

Upgraded Bullet physics in Godot to the latest 4.1.3 stable release.
Source: https://github.com/z80/ignition/archive/refs/tags/godot_4.1.3_stable_8797fdcfc1.zip
Windows binaries: https://github.com/z80/ignition/releases/download/godot_4.1.3_stable_8797fdcfc1/godot_4.1.3_stable_8797fdcfc1.zip

Geniegenii answered 13/11, 2023 at 4:20 Comment(0)
G
1

Upgraded Bullet physics in Godot to 4.2-stable.
Source: https://github.com/z80/ignition/releases/tag/godot_4.2_stable_4767fbb521
Windows binaries: https://github.com/z80/ignition/releases/download/godot_4.2_stable_4767fbb521/godot-4.2-stable-4767fbb5214.zip

It was 8 months since the first Bullet physics port to Godot 4. And while I regularly upgrade it to up-to-date version I really see no Godot native physics changes besides of a couple of lines here and there. I'm not sure about everybody else's projects but in my one it was exploding since the very first Godot physics and keeps exploding now.

Does anybody know if they consider their physics to be mature and stable? Did they abandon their physics and gave up? Is Godot slowly dying?

Geniegenii answered 4/12, 2023 at 3:25 Comment(0)
S
0

Geniegenii Is Godot slowly dying?

Talks about the death of Godot have been going on since the beginning of engine development. πŸ˜ƒ The engine is being developed, but they don't emphasize physics yet, probably not enough people. The fact that the physics is not perfect, the developers know:

Important remarks:

Going forward on the development roadmap for Godot 4, Godot Physics is an area that will continue to receive ongoing effort. Further performance optimization is in store, and you may still encounter a few kinks we’re aware of that will be ironed out in future releases.

Do you plan to support GDExtension?

Salangia answered 4/12, 2023 at 11:6 Comment(0)
G
0

Salangia Do you plan to support GDExtension?

It's currently a built-in module like in Godot3. I am porting it each time a new version is released. I tried to make it a plugin but Godot native didn't export a few enums which were in use in Bullet physics. I hope they've fixed it, I haven't checked the status of Godot native for a while. I might take another attempt to make it a binary module.

Geniegenii answered 4/12, 2023 at 16:41 Comment(0)
S
0

Geniegenii I might take another attempt to make it a binary module.

That would be excellent! There are other useful modules that are not yet implemented as GDExtension:

  • Supporting GDExtension in the future, once it matures.

Trying to use them in one project becomes difficult.

Salangia answered 4/12, 2023 at 17:16 Comment(0)
C
0

Geniegenii Sorry didn't see these replies until now! Glad that the bug information was helpful, good to see this is still progressing. I think I implemented the half height stuff in the capsule init function but ultimately it will be the same result. Deterministic physics engines are so important for physics heavy games and networked games. Its really strange to see major engines moving away from them.

Cockspur answered 18/12, 2023 at 18:31 Comment(0)
G
0

Cockspur Sorry didn't see these replies until now! Glad that the bug information was helpful, good to see this is still progressing. I think I implemented the half height stuff in the capsule init function but ultimately it will be the same result. Deterministic physics engines are so important for physics heavy games and networked games. Its really strange to see major engines moving away from them.

Thank you so much again for finding the issue with the capsule shape!

Can the Godot custom physics phenomenon be a result of the confidence of knowledge curve, see the picture attached? The phenomenon of the confidence spike near the origin might be a driving factor in making a decision to implement a custom physics engine. I find myself consistently falling into this problem πŸ™‚

Geniegenii answered 18/12, 2023 at 21:32 Comment(0)
B
0

Hi, I tried to use your Bullet port (which I highly highly appreciate) and I got this message:

While spawn_body() looks like this:

The error message is referring to the last shown line (body.instance... etc.)
This line is not doing anything at all because of this.

Burke answered 4/1 at 22:39 Comment(0)
G
0

Burke The error message is referring to the last shown line (body.instance... etc.)
This line is not doing anything at all because of this.

Ops, sorry for the inconvenience!

Just in case, would you please let me know what type your "PlayerCharacter/Camera/target" is?

Is there an easy way for me to duplicate this problem so that I can debug it?

I'm searching for "not supported by bullet". So far it looks like it is indeed not implemented in the wrapper. This is just an adaptation of the original Bullet wrapper from Godot3 to Godot4. I didn't extend its functionality. I'll try to figure out what it should do and make this function work.

Please see the screenshot attached below.

Geniegenii answered 27/1 at 1:39 Comment(0)
B
0

Geniegenii "PlayerCharacter/Camera/target" is a raycast.

Burke answered 30/1 at 19:23 Comment(0)

© 2022 - 2024 β€” McMap. All rights reserved.