Well, there were a couple of things that irked me a little during BowlMaster, which ended up causing issues in this lecture.
Firstly, the pinsetter GameObject is scaled to encompass the area required. If it’s a standalone object that’s fine, but if it will ever become a parent, than that’s a problem since child positions are also scaled accordingly. This is why, in this case, it isn’t possible to simply copy the animation from the parent to the child, since the child was parented under world when the animations were made.
To fix this (I scaled to collider to begin with so I didn’t need to do this but this should work):
- Un-parent the Swiper from the pinsetter in the hierarchy
- Copy the pinsetter scale from the transform to the BoxCollider (the collider scale will look massive!)
- Set the scale on the pinsetter transform back to 1. Notice how the collider looks ok again.
- Re-parent the swiper under the pinsetter
- Select the pinsetter and go to the “swipe” animation in the animation editor. The pinsetter should still have the swipe animation so when played it all kinda looks the same as before.
- Add the properties you need from the swiper child (I.e /Swiper/translate.position)
- Select the keyframes on the pinsetter and copy/paste them to the corresponding property below on the Swiper.
- Delete the properties from the pinsetter object. Play and be amazed how this might have taken longer that redoing the animation :).
I hope that helped (I hope it worked) :).
But while am at it… The second thing that bothered me a wee bit, was the actual bowling pin asset. It’s a bit sloppy. It has rotation and scale on the source mesh (and bad tessellation that prevents it from smoothing properly). For static meshes you want to keep translations/rotations at zero and scale at 1 so the code can assume that with all properties reset, it should have the intended rest rotation and scale. And in case you want to manipulate hierarchies you don’t want to deal with the inevitable scale issues.
As far as the pin is concerned, it’s “acceptable” as long as it is under a parent and we’re manipulating that parent but after simplifying the pin object a few lectures earlier to consist of only one node, its root translate gets some nasty rotations and scale from the get-go, which isn’t good. For instance, checking if it is standing should surely just be as easy as (pseudo)?:
If angle between “Vector3.up” and “transform.up” is within this “threshold” then the pin is standing up…
So, some best practices:
- If you’re creating assets in the editor, which might later become a parent, keep (transform) scale at 1.
- In your content creation package of choice, for static objects, reset transforms so that position and rotation is a 0 and scale is at 1. (Always create your models to scale)
- To get a clean, smooth mesh: Don’t have unnecessary tessellation which will mess up your smoothing (vertex normals). The only exception to this is if you’re baking/applying normalmaps from a hi-poly mesh and/or are using displacements.