shawn's blog

……moar clouds (finale)…..

Posted in Other by Shawn on January 28, 2011

If you noticed the interval between the clouds being generated, you would notice that they are the same. This meant if I created a level full of mostly fast clouds, even if they were at different heights, the intervals would remain the same. To add some more variety, all that was necessary was telling our clouds to spawn at random times. This meant changing the yield WaitForSeconds(int) to something that looks like:

yield WaitForSeconds(Random.Range(10, 15));

Hey! Now we’ll have clouds spawning anywhere from 10-15 seconds after the latest cloud. This actually turned out to be much easier than anticipated.

Clouds Spawning at different intervals.

Now that we have clouds spawning at random intervals, we can work on adding a bit more variety in the cloud spawning. This can be done two ways. The first way would be to alternate the types of clouds being spawned. What needed to be checked was “What type of cloud did we just spawn?”. This could be done by creating a new boolean, which I called spawnAngryCloud().

spawnAngryCloud = false;
var instanceAngry : GameObject = Instantiate(
angryClouds, transform.position, transform.rotation);
yield WaitForSeconds(Random.Range(26, 30));
}else if(!spawnAngryCloud)
spawnAngryCloud = true;
var instance : GameObject = Instantiate(
clouds, transform.position, transform.rotation);
yield WaitForSeconds(Random.Range(26, 30));
Now, we check to see which cloud we’re spawning. Initially, spawnAngryCloud is set to false, which spawns a normal cloud. Right away, we set spawnAngryCloud = true to make sure that the next time we spawn a cloud, it will be angry. I placed this script on to a fast, normal, and slow generator, which gave me:
Alternating Clouds

Again, doing this would cause consistency of some kind, something not too common within the cloud world (at least, that’s what I learn in my philosophy of clouds class). What I decided to do was reuse the Random.Range tool:

var whatCloud : int = Random.Range(2,11);

if(whatCloud % 2 == 0)
spawnAngryCloud = false;

}else if(whatCloud % 2 == 1){

spawnAngryCloud = true;

I checked the remainder of a random integer from 2 – 11, which will either return 0 or 1. If it’s 0, we’ll get an angry cloud; 1 will spawn a normal cloud. Combined with the various interval script, and we have:

Different Clouds, Different Intervals

Lovely! Now, we can create fast, slow, and normal speed generators for each of our different types of spawning clouds, which should give us much more variety than initially.

Looks like we’re done with clouds for now. Later on, I plan to include an ‘evil’ cloud that….well, is evil and potentially hazardous to objects on the screen. I wonder how that cloud will look…..

Tagged with:

Comments Off on ……moar clouds (finale)…..

……moar clouds (part tres)…..

Posted in Other 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()  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(){
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 Other 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 Other 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)…..

Work With Unity

Posted in Other 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