Black Hole Game – Spring Break Jam

How did this start?

Over this past spring break of 2017, I set up a small group project for people to do over break. This was part of the club that I am the current Vice President of, RIT Game Development Club. The process started out with a group meeting where we all picked out roles that we would like to fulfill. In the end, most people had preventing circumstances and the project fell on just me and one other person who recorded some audio for the game.

About the game

The basic mechanic of this game is that the player shoots “black holes” at the opposing player. trying to get the other player stuck and lose a life. The black holes merge together when they hit each other, creating large black holes. The larger the hole is, the more attraction force it will have. The orange obstacles are bouncy obstacles that can send players off into unwanted directions, or they might just save them from a couple close calls too.

See this project on GitHub

 

Prototype of “Ergo Witness”

 

What is Ergo Witness?

Ergo Witness is a 3D visualization of network data for a national computing security competition called CCDC. The video above is just one prototype concept that I have made in the past 6 or so weeks.

Who is the intended audience?

The intended audience for this visualization are people who understand what the competition is about, have a basic understanding of network traffic, but cannot necessarily follow all of the in depth updates through the competition.

What is happening?

The spheres represent a device on the network, and their color is determined by if they are on the red or blue team. If they are not on either team, then they are just orange for now. The teams are determined by if they have the same first 3 numbers of their IPv4 address the same. For example “192.168.137.100” would be in the same group as “192.168.137.1”.

The lines and particles that are being drawn in between represent netflow traffic, and their color varies based on the protocol.

The white glow surrounding some spheres represents their different sub net values. This is something that I have been really struggling to represent in a good way, and I am currently searching for a better alternative.

How do I get the data?

I am gathering the network data by running Bro and Packetbeat on a CentOS 7 box, and sending their logs to a Logstash server. I then make HTTP Post requests, which you can learn more about in my post here.

Why is this important?

There is a distinct lack of network data visualizations, especially interactive experiences. By using a game engine to do this there are endless possibilities for VR data visualisations that could be legitimate tools to help professionals do their jobs better. Imagine, one headset, with 360 degrees of viewing space to add as many virtual screens as the user wants. No longer would people need to but 15 different computer monitors, they could just by one headset. And if you developed for something like the Hololens, then the user can still see through to their keyboard and their surroundings. Amazing.

How to make HTTP GET/POST Requests in Unity 5 C#

Recently I have been doing a lot with GET and PUT requests to get JSON data from a server. Throughout my time working on this project, I noticed that the examples provided by Unity for using the WWW class for POST headers, is geared more towards SQL databases, and they make a lot of assumptions about your server configuration.

Why use the WWW class?

There a tons of ways to make HTTP requests in C#, like the HttpRequest Class for example. But, there is a huge problem with using classes like these at run time in Unity, and that is they run on the main thread. This means that if the thing that you a requesting is large enough (which it really doesn’t need to be that big), it can cause some pretty bad frame rates. Even if you put the request in a co-routine, then you if things fail it can get pretty complicated to handle things how you want to. Or if there is a timeout to the server, or a bad request, then everything could come crashing down.

The WWW class has several features about it that are useful. First of all, it is built into Unity, so you have that without having to look at a bunch of different documentations. The WWW class handles all the back end stuff for you, like opening and closing the data streams, with much less code. Finally, the WWW class runs on a separate thread! This means increased performance, and less chance of things hanging up your frame rate.

How to implement the WWW class

The WWW class is simple and easy to use, but you will need a couple things first if you want to make a POST request with it.

  1. A database set up on a server, whether it is SQL, ELK, or whatever other back end you want. This needs to be configured before you can do anything.
  2. Make sure that the firewall that is configured on the server will allow you to access the port or service that you need. This sounds obvious but it can cause a lot of frustration if you don’t catch it early.
  3. A Unity project that is hungry for some JSON data!

Here is a co-routine that will make a request, and wait for it to finish before moving along.

private IEnumerator PostJsonData(){
 // The URL of the server, and the port
 string url = "http://<myURL>:<my Port>";

 // The query that you want to send, read in from the streaming assets
 // This way we can just read in the Query once and reference it
 string query = System.IO.File.ReadAllText(Application.streamingAssetsPath + "/myQuery.json");

 // Create HTML headers
 Dictionary<string, string> headers = new Dictionary<string, string>();

 // Set the headers to be JSON format
 headers["Content-Type"] = "application/json";

 // Get the post data that I will be using, and encode it properly
 byte[] postData = Encoding.GetEncoding("UTF-8").GetBytes(query);

 // Create a web request object
 WWW myRequest = new WWW(url, postData, headers);

 // Yield until it's done:
 yield return myRequest;

 // Check if there was an error or not
 if(myRequest.error ==null)
 {
 // There was no error, you have your data!
 // Send that data to the Json Utility and get it parsed in a C# data object
 string jsonDataString = myrequest.text;

 }
 else
 {
 // Handle there being an error
 Debug.Log("There was an error in the request");
 }
}

Now that you have your JSON data in string format, you can use Unity’s JSON Utility class to turn it into a C# data object. I have another post about doing that here.

If you are interested in how to do this specifically with the ELK stack, then fear not! I have more posts about that coming, with specific instructions on how to configure it. For now I made a GitHub repo with a couple useful things for creating a CentOS 7 ELK stack.

Using Unity 5.5.1