Mar 4, 2016

Suzy Cube Update: March 4, 2016

#suzycube #indiedev #gamedev #madewithunity 

This week, I worked on a new title screen. I can't say if it's final, but I needed something a bit more eye catching for GDC.

It's nice in motion as the Skull enemy walks around and the camera subtly drifts, highlighting the depth of the scene.

A Bounce in Your... Hair?

Speaking of the camera drifting motion, after trying out a couple ways I could handle it using scripts I already had lying around and a couple of really simple motion attempts, I decided to write something new. 

I already had a handy script for picking random positions within an area, it's how the free flying bee enemies get around. So, what I concentrated on was the motion part, getting the camera to smoothly fly from random spot to random spot. The major problem I was having was that changes of direction were always too abrupt regardless of how I tried to have the camera float around smoothly. I also tried with easing motions, but then it gave the camera this weird, acceleration and deceleration motion which also wasn't what I wanted.

Finally, I decided to create a simple velocity based mover script. It uses very basic Newtonian principles of acceleration, velocity and damping to smoothly accelerate an object toward a target position. After a bit more playing around, I ended up with something not unlike a spring setup in which the acceleration of the object is actually set as a factor of the distance to the target, the farther the target, the greater the acceleration. This dependance on the distance to the target is what gives the motion its spring like quality.

High values lead to a taut spring effect.
In the animated gif above, you can see the effect in motion. The cube is accelerated toward the sphere, which acts as the target object. In this example, the values for maximum acceleration, velocity and the spring tension factor are all set quite high, leading to a fast and responsive spring. For the drifting camera, the values are set much lower so as the target position is randomized, the camera slowly changes course toward the new position leading to nice slow movement arcs.

And Then it Hit Me!

Since first modeling and rigging the Suzy model years ago, I had always half-intended to have her hair buns be dynamically animated. It's why I never bothered to animate them by hand, after all. After so much time, though, I never figured I would actually get around to it despite having a pretty good idea of how I would go about it if I did.

Playing around with my new spring script, though, it dawned on me that it was, essentially, half the work of creating the dynamically animated hair for Suzy. So, yesterday afternoon, I decided to just go for it!

First proxy test of the dynamic hair buns.
First, I decided to set up a proxy test just to see if I could get the desired results before poking around in my player prefab. So, I set up some boxes to approximate Suzy's head shape and hair buns and got to work setting everything up, leading to the, very promising, results above. How it works is actually quite simple.

The Setup

Above, we see a diagram of the setup as seen, vaguely, from the back of Suzy's head. The blue circles are a couple of objects parented to the head, the green diamonds follow the circles around using the spring motion script and finally, the green arrows represent the other piece of the puzzle, the look at script, more on that in a bit.

Since the blue circles are parented to the head, they move along with it.

As mentioned above, I wrote another new script to complete the effect, a look at script. Unity already has a very handy LookAt() function which I used as the basis for my script. Since the function assumes you want to point the front of the object toward the target, I added rotation adjustment parameters to allow me to rotate the buns back to the desired resting position once set up. I also added a field to allow for an object to define the up vector of the object which uses the look at script. This allows the buns to stay aligned with the head during rotations. Notice, I captured the proxy footage above before adding this so the buns are always aligned to the world up vector when the head is rotated.

Now comes the fun part. Putting it all together. The green diamonds get linked to the blue circles via the spring motion script so that when the head it moved, taking the blue circles with it, the green diamonds will get pulled along, and even overshoot when the head stops moving. Since the hair buns are set to point at the green diamonds, they end up looking like they are being dragged around by the motion of the head!

And, finally, this is what it looks like in the game using the actual Suzy Cube model.

Suzy with bouncy buns!
The motion is quite subtle given the low framerate of the animated gif, but you can certainly see it during the big exaggerated jump pad landing. It adds so much life to the character, I'm so glad I took this unexpected detour!

And the Rest

The rest of the week was spent fixing little bugs here and there and working on my GDC schedule. Man am I getting nervous/excited! I'm also glad that, following a Unity update, I can once again use my controller to play Suzy Cube on my iPod! Another good thing for showing off at the conference! Now if we can just get one last update before the show to fix the pixelated lightmaps, that would be great... Though, maybe updating the engine before the show isn't really the smartest idea.

Next week is my last before heading off to San Francisco, so the focus will definitely be on setting the game up to show and NOT on risky detours. See you all next week!

No comments:

Post a Comment