Why doesn’t my particle system show in front of my sprites??

Particle System Sort LayerThis one had me befuddled for a little while. I could not figure out why my particle system was not showing up in front of my sprites for the life of me. I had the “Layer” set properly but I could not find a place to set the “Sorting Layer”. I came across some other folks who were saying you had to set the sorting layer manually in code so the particle system would show up where it needed to (sorry, I can’t remember the references!). Okay, that seems easy enough, let’s see if we can figure that out. It looks like we can do that via the following code. The “sortingLayerName” is just a string of a sorting layer you have defined in Unity and the “sortingOrder” is an integer that specifies the z-order in that sorting layer. The higher the number, the closer the object “looks” to you.


particleSystem.renderer.sortingLayerName = sortingLayerName;
particleSystem.renderer.sortingOrder = sortingOrder;

So now let’s just make this into a script so we can easily apply it to all particle systems we create.

I put the following code into a file named “ParticleSystemFix.cs” and attached it to any particle systems I create.

using UnityEngine;
using System.Collections;

public class ParticleSystemFix : MonoBehaviour {

public string sortingLayerName;
public int sortingOrder;

/**
 */
void Start() {
    particleSystem.renderer.sortingLayerName = sortingLayerName;
    particleSystem.renderer.sortingOrder = sortingOrder;
    enabled = false;
  }
}

I’ll usually tell a script to disable itself once it is done initializing or if the code in the Update() function starts to be skipped because of a certain condition. I’m sure there has to be a slight performance advantage to doing this…every little bit helps.  Plus it lets me know if something is executing properly when I expect the script to become disabled.

Particle System Sort LayerNow, just attach this script to any particle system; there in the inspector, you can define a “sortingLayerName” and “sortingOrder” on the “ParticleSystemFix”.  I used a large number like 999 as my “sortingOrder” since I want my particle systems to appear on top of all my sprites.

 

 

Particle System Sort LayerMake sure that what you pass into the “sortingLayerName” is defined in Unity!

That is about it, as long as the “sortingLayerName” for your particle system is where it needs to be hierarchically, your particle system should appear on top of the sprites.

 

 

 

 

Some final thoughts about “Shape Sprout”

“Shape Sprout” is now live on the Amazon Appstore, Google Play StoreApple App Store and on Facebook! We are constantly learning new things every time we work on an app and at the same time, we find more ideas for other apps!  Apple took a little longer to approve our app this go around than it did last time…10 days. Amazon was only a day or two and Google and Facebook were pretty much same day. All in all, I thought the development of this app went exceptionally smooth. Very few bumps in the road from the development side…I just have to get my artistic ability up to par. Practice, practice, practice! And of course having Kari record audio for our games is such a blast; she always makes me laugh. We’ve already started development on the next app; it’s called “Jumble Attack” and is based on the hot air balloon event that happens in “Shape Sprout”. We decided on a bit simpler app this go around because we are changing how we are doing a few things and wanted to focus on getting those ironed out while still making a fun game to play. We’ve decided to go the in-app store route to allow people to purchase an ad-free gaming experience instead of having two versions of our game.  This should make maintenance a whole lot easier. Also, there will be some communications between our app and our web server. This is something we’ll use in later apps and wanted to see if we could find a good way to do that. We decided on doing HTTPS + encrypted data…then realized we have to get an ERN from the government before we could legally make an app available that implemented encryption or even used HTTPS. This was a surprise to us. Curious how to get your ERN? I’ll be posting how I did that very soon. The whole process only took about 2 days which is saying something when the government is involved. Onward and upward!

Huh? I told you to explode over THERE

So no matter how awesome a tool is, it always has some bugs in it. Unity3D doesn’t escape this unfortunate reality. So far I haven’t come across anything that was so bad it made the tool unusable, just delayed development for a little bit while I searched for a solution. One of these bugs reared it’s ugly head during development of Shape Sprout while trying to create a small explosion for when Kari’s “shape bullets” hit Jumble’s target on his balloon. So, I created a particle system, set the parameters to make it look like a little explosion, turned off looping and then created a prefab out of it so I could instantiate it easily when needed in the game. So far so good, the collider was triggering the callback function on the target and I setup up the transform location of the newly created explosion at the point that the “shape bullet” hit the target. Something like this…

GameObject bulletHit = (GameObject) GameObject.Instantiate(bulletHitPrefab);
bulletHit.transform.parent = other.transform.parent;
bulletHit.transform.localPosition = other.transform.localPosition;
bulletHit.particleSystem.Play();
Diagnostic.Logit(other.transform.position);
Diagnostic.Logit(bulletHit.transform.position);

Every once in a while though, the explosion would happen at some random spot on the screen instead of where the “shape bullet” hit the target.

Particle System Positioning Oddity
Um…how’d the explosion get over there?

What in the world? I must have been doing SOMETHING wrong, but the same exact code was running each and every time. Timing maybe? Lets move some code around where things are created and destroyed.  Nothing. Still had the same problems.  Even made a log of the location of both where the explosion should happen and where the explosion supposedly was and they were exactly the same.  So why wasn’t it SHOWING it in the right spot? I started looking around a bit online and found something about the particle system needing to be disabled first before positioning it, then re-enable it.  AND make sure “Play on Awake” wasn’t enabled. Okay, so lets add a little bit into the code here…

GameObject bulletHit = (GameObject) GameObject.Instantiate(bulletHitPrefab);
bulletHit.SetActive(false);
bulletHit.transform.parent = other.transform.parent;
bulletHit.transform.localPosition = other.transform.localPosition;
bulletHit.SetActive(true);
bulletHit.particleSystem.Play();

And lets see what happens…

Particle System Positioning Fixed
That’s more like it

Maybe this is expected “behaviour”. (See what I did there?) Maybe I’m just doing it wrong? All in all I would not trade Unity3D for anything right now. Maybe this will help someone else dealing with this odd particle system positioning bug/issue. As of this writing, I am using Unity version 4.5.2f1.

Wrapping up Shape Sprout

And here is the REAL life “Kari the Shape Fairy” play testing her new game, Shape Sprout! She loves hearing her own voice in the game. We are getting close to wrapping it up, still squashing a few bugs and testing some settings. We hope to have it out soon for Android, iPhone/iPad, and Facebook. Shape Sprout is the second game we’ve developed so far and has been an absolute blast to work on. We have SO many other ideas lined up for games, just need more time…and caffeine!

Play testing Shape Sprout
Play testing Shape Sprout
Play testing Shape Sprout
Play testing Shape Sprout

 

 

 

 

 

 

 

 

 

I’ll never use Algebra or Trigonometry, why do I need to learn it in school?

Lucky for me I enjoyed math in school, so I never asked this question. Up to this point, Unity3D has handled all the reflective forces on a rigid body so I haven’t had to do any calculations like that…THANK GOODNESS. I might like math, but I’m not quite that crazy…yet. During development of Shape Sprout, I realized that I needed to shoot a “shape bullet” from the tip of her wand out to where the player touched the screen. “Oh, that’s easy…I’ll just use Lerp() or MoveTowards()!”, I thought excitedly. That works great…until the shape bullet stopped at the spot the player touched the screen and didn’t continue on like I wanted it to.  *FACEPALM*  Ya, I really should have known that was going to happen, lack of sleep maybe? Now how do I figure that one out? Hmm…I seem to remember something about slope and  y = mx+b in algebra. No, that was slope intercept form…I need just the slope. Thank goodness for Google, there isn’t anyway I can keep all this stuff in my head. So, its y2 – y1/x2 – x1. Easy enough, we know start x and y position (wand tip) and we know end x and y position (where the player touched the screen), we can get slope! Okay great, that works now and the “shape bullet” is following the path like we want it to! Now…how can I make Kari’s arm rotate in line of where the shape bullet is going?  Trigonometry to the rescue! I already extensively use COS in the movement of Jumble’s hot air balloon, I know there is something that would help. Google to the rescue again! ARCTAN…yup, looks like we just feed it the slope and it gives us back what we need. Or so I thought. Something isn’t quite right, her arm is rotating but it is moving at a different speed than what it should really be rotating. That is when I discovered the value you get from ARCTAN is in radians and not degrees *FACEPALM*, why didn’t I know that? Luckily we have a constant we can use called Mathf.Rad2Deg so I don’t have to figure it out. Now just offset the angle slightly since our arm sprite is at about a 45 degree angle and voilà, it works as intended! Only and Indie Dev would get excited about something like this. I’m pretty sure there is probably an easier way Unity lets you do all this and I just don’t know it yet.  But, don’t say you will never use Algebra or Trigonometry.

Unity what??

“So what’s this ‘powered by Unity’ screen I keep seeing when I play your games?”

I’ve never been more excited about game development than after discovering a little tool by the name of Unity3D about 4 months ago…and I use the term “little” very loosely. Why am I so excited about it? It takes a lot of the meticulous initialization and setup you used to have to do through code and handles a lot of it for you so you can focus on the code that handles the content and game play. Back in the days of C++ (am I showing my age now?) to do something like a simple animation, you had to load the sprite sheet, determine the location and size of each frame of the animation on the said sprite sheet, create a mask so the transparent parts of the image would be transparent and create an engine that would cycle through those images smoothly.  Yes, the “BitBlt” function was my friend during those times. That doesn’t even include the collision detection on the sprite itself! This was done ALL through code and was exceptionally tedious. Unity3D gives you the ability to do all of this without writing a single line of code.  Absolutely amazing. You can now focus your code on what your character DOES instead of how to just make your character appear on screen and walk. And that’s just scratching the surface, there is so much more to Unity3D that I haven’t even touched on yet. Oh, did I mention it also has this nifty feature for building your game on multiple devices and platforms fairly easily? How else could we get our games out for Android and iOS so quickly?  I’d really love to put together a 3D game sometime but I’ll have to get more familiar with Blender for that one. “Ummm…weren’t you just talking about Unity3D? What’s ‘Blender’?” I’ll save that one for another time.

So what exactly does Unity3D look like in action? Glad you asked 🙂 One of the powerful features of Unity3D is it allows you to “play” the game during development so you can see what each object is doing and how they are reacting to their surroundings. Debugging on steroids is what I call it. It also REALLY helps to have two monitors. If you are interested in game development, I HIGHLY suggest getting Unity3D and tinkering with it.

Unity3D - Shape Sprout
Unity3D – Shape Sprout

Shape Sprout Update

So after a bit of planning, configuring and development(a little over 2 months), “Shape Sprout” our second game is starting to take shape.  Pun intended!  I was able to take some screen shots of the game.  In the screen shots, I tried to get as much variety as I could.  Just realize the game is only 75% complete.  The pictures show the menu screen, Kari planting flowers, a rainstorm, drought and the flowers being harvested.  We are really excited for everyone to play the game.  Once we have released it to the App store, Google play store and Amazon App store, we will send out an announcement. It will even be available to play on Facebook! Let us know what you think of the pictures!

Michael and Nik

IMG_0385IMG_0386IMG_0361IMG_0392IMG_0396IMG_0395IMG_0394IMG_0362IMG_0363IMG_0389IMG_0390IMG_0388IMG_0391    IMG_0387

Teaching a monkey to fly

There is a LOT that goes into the development of an app of any kind. Especially games. You’ve got to put together a plan of what your game is going to do and how it’s going to do it, figure out what kinds of media you will need for it, then collect or create the graphics, sound effects and music then FINALLY you get around to the fun part…the coding! For just two people, that is a lot of work. My strength tends to lie in the logical and less so on the artistic side. Luckily, we have the awesome music of Kevin MacLeod available to use, royalty free might I add, in our games. It’s the same with the sound effects from freeSFX. Although, finding the right music and sound effects to match the mood can be a bit of a challenge. So that leaves just the graphics…did I mention my strength is NOT in the arts? I’ve learned a lot about animations and whatnot over the last few months as our new game Shape Sprout has a TON more graphics than Shape Sense…by a long shot. I liken this to teaching a monkey to fly. Most people would probably say the monkey is falling. I prefer to take the more positive stance that he’s not falling; more like he’s falling rather gracefully.

What did you just say?

Recording audio with Kari the Shape Fairy for her games are a blast! You never really know what she’s going to say cause with a 5yr old, it is sorta hard to “stick to the script” even though she thinks WE should. I think for every 10 seconds usable audio, I’ve got 1 minute of her goofing off. She says she likes to help me, but I think she just likes hearing herself say silly things!

Kari the Shape Fairy
Recording audio for Shape Sprout

Shape Sprout?

So how’d we come up with the name Shape Sprout? Most little girls like flowers, right? Well, I can tell you for certain that Kari the Shape Fairy sure does. Just last week she decided to get the bag of potting soil out (by herself mind you) and plant some bell pepper seeds we had laying around…half the bag…because she wanted to make sure they didn’t get lonely. She’s pretty excited about the game, and so am I. She may not like messes very much, but even if you are Kari the Shape Fairy, planting real seeds with real dirt gets just a little messy.