shawn's blog

……moar clouds (part tres)…..

Posted in Unity by Shawn on January 27, 2011

pretend there’s an accent on the ‘e’

Part two had us finally creating clouds that would spawn. But left alone and these clouds would form a consistent stream of clouds. We can change this by altering the spawn rate for these clouds. Right now, the Instantiate code for clouds is in a separate function, with that function being called in Update.

function Update () {
spawnCloud();
}
spawnCloud()  is being called every time we update. However, if we left it alone, with just instantiate, we would many many (many) clouds, something we do not what, even if we wanted a foggy atmosphere. We will need to check if a cloud has spawned and wait. After we wait a certain amount of time, then we could check to see if we wanted another cloud to spawn.
function spawnCloud(){
if(!didCloudSpawn){
didCloudSpawn = true;
var instance : GameObject = Instantiate(clouds, transform.position, transform.rotation);
yield WaitForSeconds(27);
didCloudSpawn = false;
}
Initially, we set didCloudSpawn = false. Then when spawnCloud() is called in Update(), we will check to see if we should spawn a cloud. Since didCloudSpawn = false, we will set it to true and spawn a cloud right away. Now, when Update is called again (it’s called 60 times in one second I think), clouds will not spawn, because didCloudSpawn is set to true. So we must wait 27* seconds. After we wait the alloted time, we will set didCloudSpawn  = false again, allowing for an additional cloud to be spawned.
Last time, I did say we were going add a bit more variety. Well, for now, what we can do is create multiple cloud generator scripts and play with the yield WaitForSeconds line. What I did, was create three different scripts, a slow cloud generator, a normal one and a fast one. They each had different amounts in the WaitForSeconds line, which meant that different generators would spawn clouds at different rates. Which meant, after creating a few fast, normal, and slow generators, we could wind up with….

Moar Clouds!

It would be best to not place two fast cloud generators right next to each other, as this would create a bit too much consistency. So, instead, I was sure to place a slow generator next to a fast or normal one. In addition to this, not all the clouds needed to be on the same plane. They could vary in position on each axis (x, y, and z). This would mean that some clouds would appear to be bigger, when in reality, they’re just closer.

They're actually in 3D space

This isn’t all the variety we could put in. While this isn’t fully implemented, what we can do is give the cloud generator a random interval to pump out clouds. For example, we can say to the slow cloud generator “Generate a cloud anywhere from 30-35 seconds after you generated your most recent cloud” while telling the fast generator to say “Generate a cloud anywhere from 10-15 seconds after your most recent cloud”. This would cause even more organized instability within our skies.

Next time, I may try to put this feature into play, in addition to adding more code to release different types of clouds.

Tagged with: ,

Comments Off on ……moar clouds (part tres)…..

……moar clouds (part duex)…..

Posted in Unity by Shawn on January 25, 2011

At the end of part one, we finished the easier task of making the background for our clouds and picking the object that our particle emmiter will pump out consistently. Now we’re going to have to generate clouds. This can be done by using Instantiate, which is basically create.

var instance : GameObject = Instantiate( clouds, transform.position, transform.rotation);
This will create the initial cloud object. In Unity, it’s actually quite easy to apply a piece of code to an object; it’s simply a matter of drag and drop. And unlike those cloud makers that you see on the side of the road sometimes, these cloud makers needed to be invisible. To achieve this, you can create an empty game object. You can probably achieve the same result by creating a block, then turn off the rendering, but I haven’t tested yet, and this method seems a bit more practical, with less potential errors.

I know it's the same image, but it's filled with many empty game objects.

Before adding the Instantiate function onto the game objects, I had to remember to add the cloud movement command onto the clouds, to enable movement. I could then confidently (somehow) apply the instantiate script to the game objects to spawn lovely clouds.

Spawning clouds

Now we have clouds. But they’re not very exciting, albeit, clouds may not be the most exciting thing. However, if we just had clouds spawning consistently from these locations, we would wind up with a line of clouds, which end up providing a very monotonous background of clouds.
That’s it for now. We’ll look at spawning more clouds at different rates next.
Tagged with: ,

Comments Off on ……moar clouds (part duex)…..

……moar clouds (part one)…..

Posted in Unity by Shawn on January 21, 2011

If you have been following anything that has been going on here, you would have already seen clouds. If you haven’t, you can browse through a few of the older post. All of the clouds being worked on were for OriGamInc’s Project S. I guess it’s almost common sense that this game will take place somewhere among the skies.

Creating clouds in XNA are a bit different that creating clouds in Unity (go figure!). While it is possible to create 3D clouds in both, it is probably much easier to create 2D in XNA, mostly with sprites. In Unity, being a much more refined ‘engine’ (engine being used loosely, as you may not necessarily apply the word to XNA), there are particle emmiters which make it quite simple to create clouds.

For Project S, I’ve decided to work on building the environment first. In terms of clouds, there were a few options. Non-moving clouds/moving player, non-moving player/moving clouds, both moving. This is ignoring how clouds would be created (either a sprite or a particle emitter, 2D or 3D). For now, I have decided to have both the clouds as well as the player move. This meant I would need to make clouds that would rise.

A blue backdrop

First, however, the clouds needed to be in the sky, which meant I needed a sky environment. Most skies nowadays pretend to be blue. In order to mimic this, the only thing I needed to do was to change the directional light object to blue. Easy, even for me.

Next, I needed to create clouds. The normal particle emmitter simply shoots out shiny particles. While they are pretty, I needed something different. If you create a texture of some kind, you can replace the original particles with your own, potentially creating funny effects or, in this case, clouds. This cloud was the same cloud that I spawned numerous times in the XNA version of clouds. Thanks to the particle emmitter, the clouds would be shot out from a single point in various directions in the x, y, and z axis. However, they were bound by an ellipsoid, helps them maintain their shape.

A happy cloud

Creating a cloud and having it move up wasn’t that bad. All I need to do was apply a translate code

transform.Translate(Vector3(0,cloudSpeed,0) * Time.deltaTime);

with cloudSpeed being the rate at which I wanted it to move. I left this as a variable to allow me to alter the speed in play mode. One problem that occurred quickly was that the clouds moved as a stream instead of as a bunch. This would happen if the clouds moved too fast, and the Ellipsoid containing them was not wide enough. Tweaking them has left me with a decent structure. The first part was done. I had a moving cloud.

That’s it for now. Next time, we’ll spawn clouds!

Tagged with: ,

Comments Off on ……moar clouds (part one)…..

Clouds

Posted in Other by Shawn on January 17, 2011

After spending a day working with Unity, not as consistently as I would have liked to, I spent a few moments working on Project S. The end results are clouds……

Not all clouds are happy clouds.....

Despite the static screenshot, the clouds actually move, as if you’re falling. I have zero artistic talent, which means that I may will need to find someone who can draw something that looks like a cloud and not a overgrown emotional piece of cotton.

The code wasn’t bad. Most of my time with this project tonight was actually working on the sprite images outside of Visual Studio. Currently, I am loading these two images from two separate files, but I plan to eventually consolidate them into one sprite sheet. This means that I will have less content to load, which means overall load times will be….well, probably faster. Load time is pretty much non-existent, as the only think that I’m loading is ~16000 clouds.

How many clouds are there in the real sky?

Eventually, I will change the screen size maximum, but right now, it’s nice to actually have something going. More work tomorrow night, and potentially another update.

Tagged with: ,

Comments Off on Clouds

Work With Unity

Posted in Unity by Shawn on January 16, 2011

This weekend has me spending a lot of time with Unity, and working through basic tutorials to get a feel for what I can/cannot do, and what happens when I hit every button at once (mostly nothing).

A basic look at the interface

I have not created any scripts for controlling in game objects yet, which can also be implemented using methods I haven’t focused on as of now. This is my first real time experimenting with an engine of this kind. While this is a 3D engine, it is possible to develop 2D games through multiple methods. One could be creating 3D objects, but leaving the world in 2D, similar to games such as Super Smash Brothers.  This seems more difficult, as you may need to work on fully creating 3D objects, as certain objects may show all their sides, as opposed to 2D objects, who are quite lazy.

A 3D object from a 2D perspective

Another option that I can pursue, as I saw from GameDevNewbie’s website is to have a depth of 1 (in one axis) for all of my objects. This would leave me less obligated to work on making full 3D objects.

This reason why I bring this up, is because currently, I am working with Microsoft’s XNA framework to develop  for OriGamInc’s Project S. Once I started playing with Unity, I quickly thought of the possibilities of using it to work on the Project. However, if I abandon using XNA, I will lose a lot of time put into this. While I am currently learning more about XNA, I am also getting a better understanding of syntax for C#.

I will continue to use both tools for furthering my development skills, but eventually, I may find that I need to make a decision.

That’s it for now.

Tagged with: ,

Comments Off on Work With Unity