This image represents a truly epic milestone for my latest project. The not-quite-finished tower in the foreground was entirely built from within the game (as opposed to inside the Unity editor). This is something I really didn't think was possible. While I knew that Unity could potentially allow for this, my own limitations and desire to put the time in to learn the scripting skills I thought would be required kept me from having any real hopes that I could take the project to this level.
What I did not realize was just how little the UFPS assets that I was making use of would need to be altered to give me the capability to manipulate the blocks in the game with the precision that you need to be able to stack them so neatly.
A bit of explanation may be in order first. UFPS stands for Ultimate First Person Shooter. It's a set of pre-programmed assets and example scripts that allow you to quickly and rather easily get a first person game working. It happens to allow for picking up physics objects (called rigid bodies) and dropping and throwing them.
While this makes for some fun messing about, there are a number of issues with what I will call the "vanilla" behavior of this grabbing element. For one, it's imprecise. The object you pick up wobbles all over. There are some built in variables that you can change to minimize this, but it's limited on first examination. It's also very dangerous. By that I mean that as you move an object around, and especially when you first pick it up, the block you grab onto will very easily knock everything around it into shards.
Despite this I had some fun with my demo game (which you can find a link to a couple posts prior to this one), with trying to stack some blocks and make a simple structure. It is possible, just very tedious and frustrating if you want to make something cool (and not risk having it blasted apart by what feels like glitchy behavior).
Trying to build with it did give me some ideas though on what kinds of changes it would require to turn it into something you could seriously build with. And once I dug into the script I was able to isolate some code that I could see was causing much of the bad behavior. It's intended to give the grabbed object some "lifelike" motion as you move it about, this wobbling and shaking might appear to give the object some weight and heft. For some games that might be good, but for me it was bad. So I carefully modified the code, specifically commenting out (disabling) the parts that related to the wobbling and some other code that caused the block to get dropped under certain conditions.
I also eliminated some code that caused the block to quickly shift from it's initial location when grabbed to a fixed height and location relative to the player. This was the dangerous part that was making it so that as you picked up a block, it would quickly knock other blocks around it all over the place.
All of these changes, and some other minor tweaks gave me 100% better control over the block when it's grabbed and moved. So then I noticed that there were still some tweaks needing to be made to get fine grain control over the block. My game had a normal movement speed and a run speed that you can change to by holding down the shift key. What I needed now was the opposite of a run speed. So I altered the run settings to turn them into a slow-motion behavior. Now holding down shift makes two major changes. The character moves significantly slower, and the mouse becomes far less sensitive (meaning you have to move the mouse further to get the same amount of change in direction). These new tweaks allow you to manipulate the block with very fine movements.
So that leaves turning the block. When I originally pictured what you'd need to make a block game that you could build structures with, I imagined a whole host of very sophisticated keybinds for rotating the block in each direction and for shifting it in small increments, even possibly changing its size. This is the type of thing that would take a lot of sophisticated programming to achieve. I find it completely amazing that the physics and my changes to the grab script make all of that unnecessary. While certainly I can see some benefits if I can ultimately add in some of these types of features, I think it's almost better the way it works now. It's more tactile and sort of causes you to have to think and learn a skill. To get the block to turn you just have to bump it up against other blocks, or set it part way on top of one so that when you let go of it, it will fall in such a way that it rotates in the direction you need it to go. Then you pick it up again maybe move around it or farther away so that you can pick it up and orient it where you want it to ultimately be placed.
Speaking of further away, I found that once I had all this new capability, there was a significant benefit to allowing the player to pick up a block from quite a distance away from it. The early build has a 3 meter distance limitation for where you can pick up the block from. I found that if you can pick it up from a larger distance, this allows you to actually lift it high into the air, and set it down on top of a high stack of blocks. This takes some practice and a steady hand, but it works. I built most of the tower in the picture from on the ground (though at some points it's helpful to jump up onto it and make fine adjustments).
Well, I could go on for ages about this, I'm completely psyched for how this has developed. The possibilities have just gone through the roof. I'm debating now just how much I want to add before providing a downloadable version with the building capabilities incorporated. It's even got me thinking about the possibilities for a viable commercial game. My thought is that I'd like to make a video demonstration and really try and get it some exposure, find out if people like it and think it has potential.
No comments:
Post a Comment