.vanaarde

Curtain Cloth Simulation

Posted on December 6, 2023  •  2 minutes  • 424 words  • 
Table of contents

Let’s make dramatic-looking tapestries!

We wanted to create large dramatic-looking tapestries that a player could walk through while moving between these two rooms. Sounds simple enough! Let’s do it!

Cloth simulation preview

Limitations

The first thing to know about cloth simulation in Unreal Engine is that cloth is authored as part of a SkeletalMesh asset. The second is that cloth can only collide with physics bodies / collision shapes contained within that SkeletalMesh asset (it cannot collide with anything outside of its own SkeletalMesh asset).

So, if the cloth can’t collide with anything outside of the SkeletalMesh asset, how do we get the character to interact with the cloth?

How do we make this work?

The (short) answer is: we manipulate the collision objects inside the cloth SkeletalMesh from the outside!

The idea is to attach (player-shaped) collision objects to bones inside the cloth SkeletalMesh. These bones will then follow the player character around, causing the (player-shaped) collision objects to push the cloth around.

There are a few components that we need to make this work:

SkeletalMesh and PhysicsAsset

The cloth SkeletalMesh has a root bone to anchor the cloth, and a body bone to which the player-shaped-collision-geo is attached. The player-shaped-collision-geo will be able to push the cloth around.

Physics Asset for Cloth Skeletal Mesh

Blueprint with Trigger Box

Since we were only concerned with a single character entering / leaving the trigger box, we were able to keep the Blueprint simple. When the player character enters our trigger box, we cache the Pawn. When the player character leaves the trigger box, we unset the cached Pawn. The rest is taken care of by the Animation Blueprint.

Tapestry Blueprint with Overlap events

Animation Blueprint

Now finally, where the last bit of magic happens. This animation blueprint will track the player position (while the the player is inside the trigger box) and snap the body bone to the player character position.

Animation Blueprint for Cloth Skeletal Mesh

Putting it all together

Here the player can be seen entering the trigger boxes for two separate Tapestry blueprints and the player-shaped-collision-geometry immediately snapping to the player’s position.

When the player character leaves the trigger boxes, the collision geometry pops back to its “idle” position.

Future work

This mechanism could be extended to support multiple character interactions by adding more “collision bones” to the cloth skeletal mesh and extending the Blueprint to keep track of multiple overlapping characters.

Follow me

I sometimes post gamedev stuff on these social media things