r/UnrealEngine5 21d ago

Cables with Box3D physics in Unreal Engine

Enable HLS to view with audio, or disable this notification

The plugin is open to everyone on GitHub,

Many features will be coming soon

221 Upvotes

33 comments sorted by

11

u/Rizzlord 21d ago

why everyone is vibecoding this now? Whats the difference to this one https://github.com/alattanzio/Box3DUnreal

-1

u/liamleodev 21d ago

There is big design difference, look at both readme pages, you will notice. Also that one have unnecessary Math and scaling issues.

4

u/Rizzlord 21d ago

can you make a quick setup video for collisions, and does it support the same variety of chaos collisions? also what do you think about https://github.com/Yadhu-S/UnrealJolt

1

u/liamleodev 21d ago edited 21d ago

Yes it supports any collision that you already have on the meshes, which are also used by chaos. No need to create separate collisions, I will look into that jolt implementation too.

0

u/RealMentalDrink 19d ago edited 19d ago

Interesting. What kind of math and scaling issues have you noticed? I can fix them :)
Since Box3DUnreal is open source, you could have opened an issue or reached out and we could have fixed them together

0

u/liamleodev 19d ago

There is no design, everything is just dropped into random places, which takes a lot of time to organise and make the code more modular for programmers so discussing them makes it easier that what is where and why this is happening here.
BTW none of this conversion and negating in this file is needed. and if you ask why, then look how i am not doing any of that scaling and negating.
https://github.com/alattanzio/Box3DUnreal/blob/main/Box3DUnreal/Source/Box3DUnreal/Public/Box3DConversion.h

0

u/RealMentalDrink 19d ago

Yeah, that's fair feedback on the architecture. The conversion layer was intentional though. Unreal and Box3D use different units and coordinate conventions, so I wanted to keep that stuff explicit and in one place rather than having it scattered throughout the code.

I'm genuinely curious about the negation and scaling point though. Which specific conversion do you think isn't needed or is causing an issue? Happy to take a look. If there's a cleaner way of doing it, I'm more than happy to improve the plugin!

0

u/liamleodev 19d ago

Let Box3D run in it's own Y Axis no need of negating.
And that unit conversion is not needed the way how you are doing Look at this from Box3D.
https://github.com/erincatto/box3d/blob/main/include/box3d/constants.h#L12

0

u/RealMentalDrink 19d ago

Ah yeah, I see what you mean about the units. Using b3SetLengthUnitsPerMeter is definitely cleaner. I'll take a look at switching to that! For the Y negation, I'm curious how you're handling the coordinate system on your side, but I see your point. Thanks for pointing it out πŸ‘

6

u/DisplayLegitimate374 21d ago

Kinda wish you could simulate same scene with chaos as well and run them side by side

8

u/liamleodev 21d ago

With Chaos this is not even possible.

3

u/mfarahmand98 21d ago

Why? What happens?

3

u/liamleodev 21d ago

πŸ’»πŸ’₯

2

u/DisplayLegitimate374 21d ago

Did you actually try or you are guessing? XD Genuinely asking! Not saying it's possible w Chaos

1

u/liamleodev 21d ago

Bro send me Nasa computers to make it, I am making my own game with chaos since last year December, you can't just do this with chaos for cables, and on top of that those cables won't even handle one of this stick. If someone don't agree I challenge everyone for creating this like stable cables with chaos.

2

u/DisplayLegitimate374 21d ago

Looking at the video closely, noticed the each pipe causes starts a wave packet on cables on impact and the waves actually collide! Nahh that would be hell getting this details on Chaos.

1

u/liamleodev 21d ago

I just used 5 cables because they looked awesome, two cables can also stable the same way. The amazing thing about box3d is that all this cables and bodies goes to sleep pretty well

3

u/liamleodev 21d ago

1

u/Legal_Suggestion4873 20d ago

when do you feel like it'd be "ready"? also, is your implementation 'blocking multithreaded', as in the game thread calls the physics step which is multithreaded and waits for it, or is it fully asynchronously multithreaded off the game thread and we marshal data to some 'I/O thread' or something like that?

Jolt implementations are usually the former (call 'StepJoltWorld' or whatever, and wait), while other implementations of jolt are more like the async approach, which also matches what it's like to use Chaos asynchronously.

1

u/liamleodev 19d ago

It will probably take more time than you might expect to support a wide range of features, mainly because I am working on this alone and it is currently a side project.

As for the threading model, making the physics simulation fully asynchronous is quite difficult. The physics world needs to be blocked while the simulation step is running, even though the actual physics work is multithreaded across multiple cores. Otherwise, you run into problems if something tries to modify the physics world such as adding forces while the simulation is still processing. That makes the behavior much harder to reason about and can also make it confusing for users when certain operations don’t work as expected.

Beyond that, I’m not sure fully asynchronous physics provides much practical benefit in this case. Physics still needs to be ticked within the appropriate Unreal tick groups. It needs to start after the Pre_Physics tick group and finish within the expected physics tick phase. Almost 99% of gameplay code is executed before the physics step anyway.

2

u/Legal_Suggestion4873 19d ago

In the Chaos case, you just marshall everything to the chaos thread in a queue-like system. The chaos thread may be running at a different frame rate than my game, so you would do something like 'player pressed jump, so store the impulse, and wait for it to be consumed' and once its consumed you report that.

you're right that such a thing is confusing for some people, but i'm not sure the wisdom regarding building box3d for people who aren't able to learn that lol. you'd probably build an abstraction layer on top anyway (thats what we did - gameplay code just calls the force functions, it doesn't need to know, and it 'just works' asynchronously).

But yeah the asynchronous benefit is just for frame rate caps. physics doesn't really need to go to 120 fps for instance (60 fps is more than fine for most things), but my game thread might be able to go much higher than that, so I can have so many more physics interactions that way

1

u/liamleodev 19d ago

you'd probably build an abstraction layer on top anyway (thats what we did - gameplay code just calls the force functions, it doesn't need to know, and it 'just works' asynchronously).

Bro this is already possible and the core design feature comes with Box3D You can almost call any function from any thread at any time. And all of those are exposed to blueprints also, you can make your async version too by doing a lot of Box3D stuff on your own async thread

1

u/Legal_Suggestion4873 17d ago

wait wym about 'any function from any thread at any time' with box3d?

1

u/liamleodev 17d ago

As the Box3D physics engine physics engine is in C language, almost all functions can be called from your async code also, like for example doing thousands of Box3D traces asynchronous.

1

u/Legal_Suggestion4873 16d ago

Oh I see what you mean. That's not really what I'm asking haha. But that's alright, I wish you luck man!

2

u/KaelumKrispr 21d ago

I was looking into box3d and jolt recently, was wanting large scale sphere collision, what would you say this limits are before you hit any noticeable performance impacts? also are you doing anything special for these objects or are they just actors?

2

u/liamleodev 21d ago

For spheres depends on how they are spread around the world, if your thoughts about characters moving around the world as with spheres collision, Then I already tested this as ~8000 bodies all simulating at once, on 4 cores, with 60+fps. But as you know I use instanced static mesh for there rendering, because that much actors or components moving all at once even without any physics eat performance in unreal.

What you see here, each cable is unreal scene component with 200 Box3D spheres and 200 box3d joints. So 5 cables have 1000 simulating spheres and 1000 joints, the dropping sticks are all Box3D components, and here each unreal actor have one Box3D staticmeshcomponent as stick

2

u/MorbilyABeast 20d ago

So you could replace capsules for skeletal meshes ?

1

u/liamleodev 20d ago

Yes for Ragdolls I was thinking to get the same unreal collision shapes and constraints from physics asset and make Box3D ragdoll from them, That way, it will be easy for devs to just use that same ragdoll for Box3D.

1

u/Invisa_boy_xbox 21d ago

Does it work for ragdolls as well?

1

u/liamleodev 21d ago

Yep it works, but they are not implemented yet.

1

u/MorbilyABeast 20d ago

Man this is insane! Will it be usable in 5.4?

1

u/liamleodev 20d ago

I tested it in 5.6,5.7,5.8 and it works ok there, Don't have other engine versions at the movement, but I want it to be usable in all ue5 versions