[Video] Dynamically Combine Meshes In-game to form new composite Physics Shapes!

Dear Community,

I found a way to combine spawned meshes to make them act as a single larger physics object!

This video is a proof that you can indeed do this with the power of UE4 C++.

I hope it gives you ideas for your own projects!

Enjoy!

Rama

OK I have to ask - how are you doing that? :slight_smile:

Clearly photoshopped…

haha jk nice job!

very nicely done rama:)

Hee hee! I was hoping you’d ask :slight_smile:

The obvious solution of creating physics constraints, connecting all of the meshes is what I tried first.

So I picked one mesh to be the root, and all others were supplied as the second component to the constraint.

So for 5 meshes this meant 4 constraints.

But for larger numbers of meshes, anything above 3 actually, I was getting a lot of wobbling.

As I was using my in-game editor to create the constraints, I accidentally started repeatedly doing the above process to each of the other 4 meshes, making each of them the root as well, and the result was increasing stability!

So I discovered the solution by accident:


**The Solution**

Using the general format:



```

//Create new constraint

//~~~ Init Constraint ~~~
ConstraintComp->SetConstrainedComponents(RootSMA->StaticMeshComponent, NAME_None, TargetSMA->StaticMeshComponent,NAME_None);

```




I cycle through all the meshes and each one gets its turn to be the root, and all other meshes are linked to the root.

So this means that for 5 meshes there are actually 5 x 4 physics constraints being created, because I don't link the root to itself :)

This removes all wobbling and causes the boundary meshes of the shape to correctly bounce against terrain, causing all the other meshes to respond perfectly :)

**Summary**

1. Using LCM and ACM_Locked

2. The distance for LCM is the measured distance between the meshes that are being joined by a constraint

3. Every mesh is given its turn to be the root and all other meshes are joined to it


**Performance**

On my machine, I start to get some fps lag after about 10 physics kinetic combinations are made that each have around 20-ish meshes each.

So this means 10 x 20 x 19 = 3,800 total physics constraints


For my game purpose of giving the user the ability to generate their own physics combinations,

and then romp around on them, 

and have those physics combinations intereact with each other, ~4,000 constraints is perfectly reasonable!

Final Summary

UE4 Physics Engine is Awesome!

Rama

I have one question about it. Can i access from one actor connected by PhysicsConstraints to another connecter actor?
For example i have my AActor class with property: float temp;. I create two instance of this actor: A and B.
I link them together with PhysicsConstraint.
Can i acces to B temp property value from actor A?

Actually in 4.5 you can use the new Body Welding feature!

When you attach actors make sure the welding option is enabled!

See actor.h AttachActorToActor for more info!

Nice job Rama! This opens a realm of possibilities!

Your man is no longer naked!!

Very nice to hear from you !

He often keeps his rainbow armor in magical storage! :slight_smile:

Dx11 Tech Demo in UE4 (Beta)

:slight_smile:

Rama

Haha!! Great work man. :slight_smile:

So Rama, i should use 4.5 engine than 4.3.1?
This is my problem, when I trying attach actor to actor:

It teleporting second actor somewhere :stuck_out_tongue:

When you attach, use EAttachLocation::KeepWorldPosition

see if that helps!

Glad you like! Hee hee! :slight_smile:

Rama

Hello, i try to utilizie your physics constraint tutoria:

this is effect:
https://www.youtube.com/watch?v=oSI8...ature=youtu.be

And I am totaly not know why my constrained blocks are that much flexible and not solid like in your videos

This is how I set limits with your functions:

SetAngularLimits(ConstraintInstance, 2, 2, 2, 0, 0, 0);

SetLinearLimits(ConstraintInstance, false, 2, 2, 2, 100);

Hi!
Is this still the best method to rigid constraint multiple object or in recent years there has been progress?

(maybe something like this: Trello but i don’t get if this is actually what i am searching for)

Thank for all the wikys and sorry for the english (: