Hey so I wanted to bump this tread because this seems to be a fairly requested thing to do. I sat down this weekend to figure it out for a few reasons, and it actually worked pretty good, but I wanted to get some feedback on a few hacks I had to do to get it to work.
So basically I made an independent BP with all of the logic calculates and handles all of the positions. Now, I had to custom tailor a few things based on the data I was working with and I imagine most people with need to do the same, but this is the general idea:
- Put the BP in the level at the center of where you want the parts to explode away from (usually the center, or in my case a little below center of the parts.
- In the BP, store the location of the BP itself, and make an array of all of the datasmith parts you want to explode. I just got the parent datasmith actor and got all attached static meshes.
- Store each position of each mesh at rest.
- Derive the actual center of those meshes and store those as well ***
- From the center points, trace back to the BP and reverse the direction of the vector and store those vectors
- Derive the distance from the BP to the center of the parts and set a distance multiplier to adjust how far each part moves
- Make a timeline that moves each part away from the center of the BP a certain distance away based on the direction and distance we calculated earlier.
- When the timeline completes, save each position of each mesh again as the exploded position.
Past that, you can setup whatever grab functionality you want, and just determine whether you want the part to fly back to its exploded or resting position. I didn’t need the gravity thing people wanted to do, but you could very easily set that up.
So about the hacks. Step 4… I really didn’t have a good way to calculate the physical center of each part. I tried to get the origin of the bounding box, but the values for that node seemed to be in local space maybe? which didn’t make sense, nor could I switch it to make it work anyway, so no go there. The hack I ended up doing was to get the world position of the actor and its forward vector, then get the box extent of the static mesh and calculate backwards to find the center point…ish…
Its hacky because that’s not going to work for everything, and it was really a fluke it worked for the data set I was working with. Is there anyway to get the world Center position of an actor? Not the 0,0,0 but the center point of its bounding box in world space. Or a proper way to calculate it with the bounds nodes. It seemed like all of the info I needed was there, just couldn’t figure out how to put it all together.
Bonus question! In one assembly I exploded, there was 1 mesh that, no matter what, would always move in the opposite Y direction than expected. I ended up having to do an override on that part to switch the direction. I don’t even have a guess as that what caused that.
tl;dr : Whats the proper way to get the world center position of a static mesh actor’s bounding box?