Monday, August 31, 2015

Unity3D At Home Project - Day 4 - Basic Animation

Busy weekend, busier week, but I did manage to sneak in a little bit of time on Sunday to play around with simple animation, and to get our avatar animated.

Tuesday, August 25, 2015

Unity3D At Home Project - Day 3 - Basic Camera Controller

So I finished off Renaissance Coder's character controller tutorial (you can find it here) with implementing a basic camera controller.  And by basic, I mean really basic. You give it a target, and it slaves its position to the target, plus an offset that you give it. For orientation, it just interpolates from its current orientation to that of the target. Even though it was a fairly small piece of code to write, I still learned a few interesting things, and had some hiccups.

Cool Things

Mathf.SmoothDampAngle
This does rotational interpolation for you. You give it a source value in radians, a destination radians, and some time values that determine how fast you want the function to interpolate towards your destination. It returns an updated angle, and also modifieds a turn velocity float that you can use in successive updates.  Really handy function.

LateUpdate
I'd forgotten about LateUpdate, but this is an update function that occurs each frame after normal Update and all of the FixedUpdates. By updating the camera position and rotation in this function, we ensure it happens after the other updates.

Hiccups

My initial offset for the camera position had the sign of the Y offset reversed, which placed the camera somewhat inconveniently underground. While cool and interesting, wasn't exactly the effect we were going for.







The other thing I noticed immediately after my first test was that the camera was still facing straight ahead - not actually looking at the player. The tutorial had mentioned an X-tilt factor, but had failed to ever actually hook it up and use it. I converted the value to radians, applied the rotation to the target's X rotation (which is always straight ahead), and then used the editor to adjust the value until  we got to something close. What was interesting was that when I changed display resolutions, the amount of avatar in the camera field of view changed. Which goes to show you the kind of BS you actually have to deal with when building a real camera.

You can see the functional camera below.



Notice my gravity quotient is way way too low, so when I go sailing off the tops of hills, I only sort of gently float back to ground over time. Also notice even the leaves of the tree have collision, lol.

What next?
Well I'm not 100% sure. The camera controller is functional, but only barely. There's no orbit control, and there's no collision. But building a robust camera controller can be a pretty dark rabbit hole - correclty and intuitively handling camera collision is a non trivial task.  So I could leave the controller alone, and move on to animation. But by the same token, the current camera is by no means near adequate, so we'll have to see.

Monday, August 24, 2015

Unity3D At Home Project - Day 2 - Simple Character Controller

So the  Standard Assets pack comes with a 3D character controller right out of the bag. And it's fairly functional - does everything you want it to do.  In fact, it's actually a little more complex than I want for first pass.  Their 3rd Person character controller contains separate components for the Controller, an Input Controller, a Camera Controller, and an Animation component, and contains code to handle interactions between all of those.

I'm trying to put pieces together piece by piece, so what I really wanted, to start with, was just a very simple character controller. Renaissance Coders YouTube channel came to the rescue, with a great, nofrills character controller you can code up in literally about 20 minutes.  You can find their tutorial here.

This allowed me to get a simple, functional character controller up in the afternoon, and I completely understand all the pieces. I also added a capsule collider to my avatar mesh (Ethan), so he would collide with the trees as I moved him around.  Once I added the capsule collider and set it's offset appropriately, I could turn on gravity on the RigidBody.  

One other interesting thing I learned here was that you need to freeze rotation on the rigid body in all three axis. The first time I tried to move poor Ethan, he fell flat on his face, and then I could only move him up and down. We have zero tie-to-ground code here, so if the unit runs up against the tree, for instance, it only slowly moves back down to the ground, based on gravity.

This controller is super simple, and there's a billion lines of code to write here for it to become an game-ready controller, but it fulfills our purpose of being able to move the unit around.

Here's a video:



Unity3D At Home Project - Day 1 - Terrain

I wanted to start with a simple terrain, using stock assets. Worked my way through a three-part tutorial, creating and sampling along the way. Stock assets provides a nice small sample of terrain textures, trees, and grasses. Very limited, but enough to play with.

Terrain was created, and I played around with the height tools, and foliage creation tools. Biggest disappointment was that I see no way of doing height-limited painting. I'm sure there are some third party tools that provide that, but it was a nice default feature in Torque.  I dropped in Ethan, the stock character, for reference.

I also created and set up a light procedural skybox. Options are available for three different kinds of skybox, but the stock assets sadly don't provide any skybox-ready textures.

Ethan - Lost in the Weeds!


Unity3D At Home Project - Introduction


So, I find myself at a curious point in my professional career. By now, you probably know (or should) I'm a game developer. I work at Robot Entertainment, where I get to work on some pretty fantastic games. Right now, I am the Project Lead for the dashboard. The dashboard is the application you use to launch the actual game. It handles all your inventory, your decks, provides access to the store, etc. In short, it's a pretty darn big project in and of itself, and its written entirely in Unity. As I've been working on it for over 15 months now, I've become pretty proficient in Unity. But, the dashboard is an application. And while it's got some very game-like aspects to it, it is not, strictly speaking, a game in and of itself.