Snow Leopard!?

September 27, 2009
by Nathan Whitehouse (nw08)

A few days ago I was trying to change some of the code in the aim script. Nothing seemed to be working, and I didn’t know why. And then, at one point, I made a considerable syntax error, without noticing, saved the script, and ran it. Nothing changed. So when I noticed the error, I started to get suspicious. Typing random gibberish into the script did not make it crash, and new variables added didn’t appear.

Apparently that error I mentioned last post that was coming up but didn’t seem to have an effect was actually preventing any other scripts from compiling until it was resolved.

Then, a few days later, scripts weren’t compiling again. Apparently snow leapord, which I just upgraded to, has this problem where it will change the caps on some files. I don’t know if there’s a reason for it, or it’s a straight up bug, but Unity gets really confused when this happens. So no more uppercase in script names for me.

I’m still not sure what to do about models and level design… I’ve started work on the AI’s ability, but pretty soon I’ll have to make a decision.

Also, finding 3D models isn’t too hard. Finding animated ones is… so I’m considering a schedule change, switching week 5 (level design) with week 4 (enhancing the AI)


Pausing, Aiming, and moving on

September 22, 2009
by Nathan Whitehouse (nw08)

So, the code I posted last time for the pause function had an obvious error in it, but one which was not actually related to the problem I was having (a lot of iterations of the script were being made). The problem being that the second if should have been an else if; otherwise, both if functions would end up being true.

The goal was to pause the game; in a paused state the world would not move, and the the user would be able to use the mouse (during normal gameplay I locked the cursor to make it impossible to accidentally click something when giving mouse input),

The problem I was having, however, was slightly more complex. For some reason, setting Screen.lockCursor = true did not seem to have any effect except in start (Screen.lockCursor does exactly what it sounds like; it returns whether the cursor is locked, and can be set to true or false as well). Part of the problem was figuring out the best way to define the function. Errors like the one I mentioned at the beginning of this post confounded the situation.

What ended up being the main error was the key I was trying to use. I had been trying to set ‘escape’ as my pause key. What I didn’t realize was that in Unity ‘escape’ also has the built in function of unlocking the cursor. A key like that is necessary; otherwise I could write a script which locks the cursor but does not provide a way to unlock it, making it impossible to pause the game or shut down the program by normal means. The moment I changed my pause key to “p”, things started working. Not everything, but most of it.

Right now, pause is almost complete. When paused, the player can’t fire, move, or change weapons, and all physics freezes in its tracks. All of this is done with manual checks (so the weapon firing script checks to see if the game state is “paused” before running). For some reason, an error gets put out to the console from the FPS controller script saying it can’t identify the GameStateController (as I posted earlier, gamePaused is a ‘static’ variable, meaning that it can be accessed by any script, and always has the same global value for all scripts. GameStateController is the name of the object to which the script containing gamePaused is attached). This error does not seem to cause any gameplay errors, so right now it’s mostly an annoyance.

I’ve also added the foundation of an aim function. The idea is that the player can hold a key to look down the sights of a weapon and aim more accurately, at the expense of movement speed and or field of vision (which is blocked partially by the weapon). Actually implementing the aim mechanics was simple. While a key is held, the weapon is relocated and re-sized to a graphically correct place, while the spread of the weapon and the motion of the player is altered. The problem is making it look pleasant. In the current implementation, the weapon simply appears instantly in the new position. Of course, it would be infinitely more preferable for the weapon to move smoothly from its regular position to the aiming position. I attempted several ways of doing this with scripting, but they were complicated and prone to failure.

So I asked how my brother (half of dastardlybanana.com) had achieved smooth motion into an aiming position, and was told that they had attempted the same thing I had, but found it just as unwieldy. He ended up creating an animation for the weapons that brought them into the correct position.

I’ve been purposefully avoiding animation in favour of code. When I was first outlining the project, I planned to use as little of it as possible, so as to have more emphasis on the coding. There are some clear limitations to code alone, however, especially in something as visually dependent as a game.

Furthermore, a lot of the stuff I want to add to the game now is not the player but the environment. Next week I start the AI for the game, and for the AI to do smart and clever and tricky things I think it needs an environment in which to interact with the player. Chasing the player around a huge open field is no good, but maybe long corridors, yes. And maybe the player can close doors, and try to lock them, but the AI can open them if the player forgets to lock them, or can go reset the locks somehow. A lot of these obstacles and environment pieces are going to have to start appearing in the game now.

There’s a lot available online, both free and paid (I’m willing to shell out a little for a nice bundle of multipurpose assets) so I shouldn’t have to do any modeling myself. I’ve started looking, and many aren’t animated; or, alternately, are much more expensive animated. If all I want is a futuristic door to slide open, I should be able to animate that myself. So it looks like I’ll be doing some crash course animation over the next few weeks. I’m not sure yet if/how I will adjust my schedule, if that turns out to be necessary – I don’t want to test the AI in an open field if I do not expect to put it there, for example.

It also means making some decisions about setting and theme which I’ve been putting off. Are we in a the future or the past? Indoors or outdoors? Obviously the project ultimately about the knowledge gained, rather than the final product, but even still, the final product should have focus. A lot of this will depend on what models I can find, and what is inexpensive (the free stuff is not exactly thematically consistent.. you’d have to mix and match to get anything.)


Catching up

September 16, 2009
by Nathan Whitehouse (nw08)

My name is Nathan Whitehouse, and I’m a sophomore at Hampshire doing an independent study on video game design in the Unity 3D environment (www.unity3d.com), with a focus on AI.

This is my first i3ci blog entry, but before this I started a blogger blog to follow my progress. Originally I was worried about the fact that i3ci blogs didn’t yet have security certificates, which might scare some people off, but it looks like that’s about to be fixed.

The old blog can be viewed here: http://unitygame.blogspot.com/

To summarize what I’ve done so far, however.

I’ve implemented two basic weapons which are able to fire with variable spread patterns, which the player can switch between at will; there are targets which have health and which can be destroyed. A lot of time has been spent trying to make sure all this basic stuff is optimized for future use; there are many easy methods to code the ability to switch between two weapons, for example, but many of them become complicated, confusing, or impossible if more weapons (and more variety in weapon function) is added later. So weapons, for example, are tagged and immediately placed into an array (variable right now, but once I know how big I’ll want it I’ll change it to builtin), and switching is done entirely by cycling through the array in a forloop.

Right now, what’s proving tricky is pausing the game. There seems to be no clear way to do it in the unity API, so each individual script needs to have a pause condition. Most rigidbody physics calculations can be stopped by changing the global ‘timeScale’ variable to zero. This does not, however, stop all types of physics, and update is still called in scripts, making it possible to continue to mouselook, for example. So in every script I’ve had to add in an if statement a check to see if the game is supposed to be paused. I’ve done research, and this seems to be the way to do it, although the trick is I suppose minimizing the number of times the conditional needs to be checked.

Helpful in this are Static Variables. A static variable is defined once, in any one script, yet can be accessed and changed from any other script. So here I have a static var called gamePaused. It’s only changed in one script right now, the GameStateController script, but any script can access it, so checking the variable is easy.

What’s giving me trouble is an error I just can’t seem to figure out. I’m going to bang away it at a little more before posting the whole thing, but essentially the cursor won’t seem to lock once it’s been unlocked if I try to use the same button to lock it as I do to unlock it (IE.

if(Input.GetKeyDown(“escape”)){
if(Screen.lockCursor == false){
Screen.lockCursor = true;

}if(Screen.lockCursor == true){
Screen.lockCursor = false;

}

) That’s essentially the code.


Hello world!

September 14, 2009
by Nathan Whitehouse (nw08)

Welcome to i3ci. This is your first post. Edit or delete it, then start blogging about your cool Computer Science project!