UE4 Interactive Physics-Based Foliage – Dev Enabled

Welcome to my first blog post, it’s only taken more than a year but I think I’ve found an interesting topic to start with, Physics Constraints.

This short tutorial post comes from one of my favourite features I’ve implemented into my Epic Mega jam entry, the wobbly bush thingy.

It’s worth noting before getting into the meat of this process that this is not going to be suited for use with abundant foliage or the terrain foliage tool inside of Unreal. This was developed with sparse usage in mind for some extra visual detail in a scene.

This idea was actually inspired by various indie racing projects I’ve seen being developed inside of Unity and they add this cool wobble effect to things like the cones and speed barriers and I was interested to see how it could be recreated in Unreal.

This process can almost certainly be optimised and if I get the chance I’ll be sure to revisit this, make improvements and post my updates. If you’re still here though, let’s get started making some cool wobbly things…


I’ll be using Blender 2.8 for my process but you can use any 3D modelling tool that allows you to apply an armature/skeleton to your mesh.

The first step is to create the mesh we wish to apply the skeleton to and then in this case inside of Blender I’ve simply applied the skeleton with automatic weighting applied.


As you can see from the images above, I’ve gone for a very simple design and the skeleton is made of just two bones, the root bone and the bone to support the main part of the bush. I’d recommend following along with a similar setup, for now, to get an understanding of the process and then build upon things when you have that nailed.

With your asset modelled and rigged export things and let’s get this into Unreal.

Unreal Engine

See, I said we’d be in Unreal.

Inside of Unreal be sure to import the new mesh with correct options to bring it in as Skeletal Mesh.

With that done, open up the PhysicsAsset version of the mesh, you’ve just imported from your content browser. This is the icon of your mesh with the orange underline. Alternatively, you can open the mesh as usual and navigate to the Physics tab in the top right of the screen.

By default, you may be met with collision looking something like in the image below on your physics asset and that’s bad, we don’t want that.

To rectify this simply select the purple collider or colliders if you have more than one and hit delete. You’ll now have a clean physics asset ready to go.

On the left side of your screen navigate to the root bone of your mesh and add a Sphere Shape. This will act as our reference to act as the root of the mesh to keep it grounded in the world and also as the hinge point of the moveable top part.

Select the new Sphere Shape, hit the R key to enable the scale widget and scale the sphere down pretty small.

These next steps are important to stop the object falling through the floor when we place it in the world later so let’s move over to the Details panel and make some updates with the new Sphere Shape selected, it should currently be called None and that’s fine.

With the Capsule created you’ll need to modify the form to match similar to what I have below. It’s not important for this style of interaction to match the collider to the form of the mesh, we just need something small and light to knock around.

Also, note that there’s actually a small gap between the Sphere and the Capsule. I found this helps to keep the trunk looking as though it’s stuck in place whilst only allowing the bush to move.

Now we need to constrain our Capsule to actually remain close to the Sphere when we simulate physics so let’s add constraints!! Right-click your upper part of the mesh, select Constraints and select the lower part of the mesh as the constraint target.


Limiting Physics

We can now begin the fun process of tweaking our physics settings to get the kind of bounce and wobble we want for our given object.
Begin by selecting one of the new Constraint objects in the Skeleton Tree window. If you’ve followed exactly then you’ll have two but they’re duplicates of the same object which will manage the same constraints so select either.

First, we’ll go to the Angular Limits section in the Details panel and set everything to Limited and I’ve chosen to set both Swing Limits and the Twist Limit to 1.


We can begin testing our results by using the debug simulation options. Inside of any Physics asset you can start a simulation by pressing the Simulate button on the toolbar and then affect the asset by holding Left Shift + Right mouse click/dragging whilst the mouse is hovering over the capsule collider. This can be a little finicky in this setup due to the size of the colliders.

This isn’t quite right, the bush looks a little more drunk than just wobbly…

To make the final corrections we can go to the Angular Motor settings still inside the Details panel. Change the Angular Drive Mode dropdown to Twist and Swing. Be sure to tick Twist and Swing under Target Orientation so that we can update the Strength to something like 500 to begin. Finally, tick the Twist and Swing boxes under Target Velocity and set Strength to 100. You can then update these values to get the results to your liking.

OK! Let’s test this again.

And that’s pretty much it. Drag your Physics Asset straight into your level and make sure to tick Simulate Physics under the Collision settings. You can now tweak things to meet your requirements, try adding some extra bones and constraints but just make sure the object collision is set to Block anything you want to affect it such as the player, enemies, projectiles etc.

A couple of tips to leave you to experiment with:

  1. Try disabling Block World Static and World Dynamic to avoid the asset colliding with and getting stuck on floors to avoid drastic bouncing.
  2. You can change the weight of the Capsule Shape to make the object feel heavier or lighter.

I’ll be releasing the full source to my Epic Mega Jam submission as soon as I’ve had the chance to tidy the code a little over on my Patreon page so consider supporting to help allow to focus on making more content like this.

Thanks for sticking around to the end.


Source link

Leave a Reply

Your email address will not be published. Required fields are marked *