Wednesday, February 1, 2017

Slicing Meshes in Unreal



Hey there!  So, for my last Tech Design assignment, I wanted to cut something in half.  For this assignment, we were supposed to create an experience using Blueprints.  We were then supposed to provide 5 enhancements.  Wanting to cut something, I figured I would try to recreate aspects of the plasma cutter from one of my favorite games, Dead Space.  There is a very deep emphasis on dismemberment using weapons in that game.  First, I looked into getting the aim sight look with the laser beam correct first.  What I did, was take a material and attach it to a particle I created.  I then would raycast from the gun and set the particle start point to the gun and the end wherever the ray is colliding.  As you can see, this works in the above gif when only one of the lasers is not colliding with the shelf.  Here are the blueprints of the laser below.  Note, it takes an input, so I am not reusing this code three times.

Now, onto the really interesting challenge.  In the unreal engine, there is a component called a Procedural Mesh.  In order to slice a static mesh, this must be a child component of that actor.  One important thing to remember with this component, is to have it not use complex as Simple Collision in it's options.  This prevents the whole thing from working.  Next, make sure that the parent is not doing any of the collision since we are having the procedural animation take the hit and split the parent into what is two separate meshes.  Next, if you want to continue slicing those meshes, one needs to make the constructor of these newly spawned meshes to have a procedural mesh and to be spawned with collision enabled.  Next, what I do, is make a collision trigger this slice.  I fire a bullet out of the gun, so when the component begins overlap with this bullet, it will call the slice method on the procedural mesh  which will spawn the new mesh after preforming the slice on the old mesh.  This slice can be seen below in the gif.

Another fun thing I did here, is I made these boxes the enemies in the game.  Once a box has been sliced twice, it kills this enemy and makes it inactive on the board.  If the player comes in contact with one of these and the enemy is still active, it will kill the player.  However, making these boxes enemies posed a new challenge.  Once the I attached the procedural mesh as a child component to a static mesh, which was a child component of a character actor, this no longer worked.  I wanted so badly for the enemies to have AI and to chase the player when they got close.  So, in order to work around this, I realized through debugging, that the collisions were not triggering correctly.  I got collision working, but even though slice function was being called, the box remained in one piece.  I eventually came up with a solution to make the character class it's own actor and then I made a sliceable mesh actor a child of the character actor.  This made the parent move the slicable box when the AI chased the player.  It took a very long time to discover this and I would like to continue researching this in the future.  I would like to eventually dismember character AI with more complex models than cubes.  The slice blueprint is below.



This was a very cool project where I got to flex my muscles as a coder to achieve some designs that interested me.  Also, I got to code in C++ and have those classes communicate with blueprints in unreal to keep track of my ammo which is seen on a widget at the bottom of the screen in the gifs above.  I also got to integrate Wwise into this project for some dynamic audio with the enemy chase moments.  Wwise is such a cool program to work with.  This project was a ton of fun to pull off and show to my peers.  That's all for today.  Thanks for reading!  More cool things to come!








No comments:

Post a Comment