Sunday Experiment - Can Pigs Fly on Mobile?

People have been asking me if When Pigs Fly will ever come to mobile ever since the initial game jam release.  I have always quickly dismissed the question, assuming that the performance would be too poor to be worthwhile.  For my Sunday experiment this week, I decided I should confirm my doubts.  The results were pretty surprising.  In fact, on one device, the game ran better than it does on the laptop I use to develop it.

Screenshot Saturday - Bomb Targets

Ever since I debuted the para-chickens, people have been asking me what they're supposed to use them for.  I don't think para-chickens really need a purpose, but one of my favorite things to do with them is try to drop them as precisely as I can.  This week I added bombing targets to make this easier and more fun.  The targets detect when something is moving nearby and automatically pop-up a target camera.  The camera stays up so you can see where your "bombs" hit, then automatically hides itself.  They also record your most accurate drops, but I haven't set up the UI to display this information yet.  Here they are in action:

Carpet Bombing

Dive Bombing


When Pigs Fly - Drag Race Challenge!

Its time to do another challenge!  We're going to do another speed challenge, but this time we're going to take advantage of the drag race course to limit entries to sustainable, controllable designs.

To enter, design your racer, then fly through the drag race course as quickly as you can (turn left after takeoff to find it).  Take a screenshot of your score after you fly through the final gate, then submit it in the comments here, over on gamejolt, or in a tweet to @GaudinoGames on twitter.  Don't worry if the score disappears.  Just fly through the course again and your best score will be displayed.

The top three entries will have their designs included in a future update of the game!  The deadline for entries is Sunday, March 8 at midnight EST.

Go get started!

Sunday Experiment - Endless Terrain

In the original version of When Pigs Fly, actually building a working airplane was pretty difficult. As a result, the map could be pretty small without worrying about running out of room to fly.  As I improved the flight model, added better parts, and people generally got better at the game, the map quickly became too small.  People were building planes fast enough to cross the map in under a minute.  Eventually I replaced the map with a much larger one.  This alleviated the problem a bit (it now takes 10 minutes or so to fly across the map in an average speed plane), but it didn't completely solve it.

Ever since that first map, I've been trying to decide what my solution is going to be.  I've thought about making the world wrap around, so when you fly off one end of the map, you warp to the other side.  I've thought about replacing the 'flat' map with a globe, so that you can actually fly around the world.  Today, though, I wanted to experiment with endless terrains.

How it works

The terrain in When Pigs Fly has always been generated at runtime (using my WIP low poly terrain generator).  But since I always use the same seed, the terrain is always the same and is static once generated.  My terrain generator works by building a flat grid of triangles, then setting the height and color of each vertex based on a height map (procedurally generated or otherwise).  

This morning, I replaced the height map with a very simple perlin noise implementation.  I also added some code to the terrain system that monitors the position of the player.  When the player moves past a certain distance, the terrain is recalculated with a new offset to remain under the player. Here is an exaggerated example.

Why this isn't a good solution

Terrains in when pigs fly are low-poly and vertex colored.  The nature of this system means that when the terrain is recalculated, if the x and z values of a vertex aren't exactly the same, its height and color will change.  I did a few things to fix this problem, but it still isn't perfect.  I could do more to make sure the terrain respawns on an exact grid, but that still wouldn't fix the next problem.

The entire terrain mesh is regenerated every time, meaning that I am wasting resources rebuilding parts of a mesh that already exist.  In my small scale tests this wasn't a huge problem, but I imagine it would become an issue in game.

What I'll probably end up doing

I think it would be better to generate new "chunks" of terrain as the player nears the edge of the map, and delete them as they get far away.  This way there would be no time wasted generating things that already exist. It would also solve the issue with exactly matching vertices.  It should be pretty easy to implement this system, as the current terrain is already split into chunks to stay under Unity's maximum mesh size.  I think draw distance is really important in flying games, so I also want to experiment with an LOD system so that the terrain truly stretches to the horizon.

The Plywood Pig on a Larger Scale

I had a few spare minutes this morning, and it was really bothering me that my Spruce Goose recreation wasn't as majestic as the real deal.  So here's a bigger one.  I think I nailed it this time.

Next time I have a break, maybe I'll use the powered hinges to make an amphibious version!

Update: Amphibious pig!

Second Update:

Pig carrier!

Clearly I need to develop some sort of arresting system.

Sunday Experiment - Buoyancy and Seaplanes

For this week's Sunday Experiment, I'm revisiting something I briefly attempted during the original jam dev session of When Pigs Fly.  The first iteration of the map in When Pigs Fly had a lake, but I ended up removing it for a couple reasons.  First, I simply didn't have time to add a buoyancy system.  Second, the animated water I made was pretty resource hungry, and I didn't have time to optimize it.

Since the jam is over and I'm no longer restricted to always writing new code, I'm now able to take advantage of some of my previous work.  This morning I grabbed the water system from my WIP low poly terrain generator and the buoyancy systems from Hoist and threw them in to WPF. An hour or so later I had a working sea-plane using blue barrels as floats.

The water object deforms its mesh based on Perlin noise.  It has a public function called GetDepthAtPosition that takes a Vector3 position and returns a float depth.  It works very simply by comparing the y value of position with the perlin value at the (x,z) values of position.  We'll use this function later to calculate the buoyancy forces on the barrels.

Each barrel has a few child "Depth Checker" gameObjects.  The positions of the children are fed into the Water.GetDepthAtPosition function to determine their depth.  That value is then used to calculate the buoyancy force using archimedes principle.  Doing it this way causes the barrels to react correctly to waves.

I then quickly threw together a particle system that emits when the average of a barrel's depth-checker children is greater than 0.  It also sets the velocity and size of the particles based on the velocity of the rigidbody.  

For the second week in a row, my Sunday Experiment has resulted in something that I really want to add to the game.  This water system is too simplistic though, so it won't show up in v0.3 as is.  In fact, I'll probably have to wait until I flesh out a couple other systems in the game before I can add this one.  While it works in this example, I know that players would find a way to break it.  Off the top of my head, I can think of people trying designs with rudders on the back of their floats.  In the current system, they would act like they were normal rudders, moving through air rather than water.  For this to work, I'll have to find some way to integrate the depth-checkers with the aerodynamics system.

Update: You've seen the Spruce Goose.  Now meet the Plywood (and plastic) Pig!

The Hinges Are Coming!

Contract work has kept me from getting as much done this week as I would have liked, but I have made some progress on a feature that I'm pretty excited about.

In the last update (0.2.1), I introduced flywheels, the first moveable part.  Flywheels just spin freely and were extremely simple to implement (just changed the angular x movement from locked to free in the ConfigurableJoint settings).  I'm now adding more complex moveable parts.  First up is the powered hinge, which is just what it sounds like.  

I've pretty much finished the physics setup and related code for the hinges.  Currently they are able to rotate 90 degrees, but I'm thinking about making this user adjustable.  In any case, I think they'll max at 180 degrees.  They move in response to user definable keys (using the same system as parachutes, parachickens, and detachable parts).  

One thing I haven't decided yet is what the hinges are going to look like. So far I've been choosing parts to look like farm/garden equipment (in the case of engines) or shapes that could easily be cut from scrap wood.  I haven't thought of any hinges that fit that bill. In the prototypes I have just built the hinges directly into boxes and long boxes with no separate model, but I would prefer them to be their own distinct part.  If anybody has any suggestions for farm/garden tool hinge analogues, please send them my way.

Here are a few of the things I've been using hinges for this week:

  • "Walking" multirotor

  • Tilt-rotor with improvised propellors

  • Tilt-rotor that actually works


Flywheels and props

The new flywheel part is useful for a variety of purposes, but the real reason I wanted it in the game was for building big props and rotors.  

Be careful, though, because unintentionally flexible props have a tendency to smack things.

Sunday Experiments - Banner Towing

I have a habit of spending my Sunday mornings messing around with experimental new features in my projects.  For me, its a good way to clear my head. It kind of allows me to get away from the project while still actually working on it.  Today, I played around with a feature I've been dreaming about since before I even started work on When Pigs Fly: banner towing.  I have long wanted to have banners hidden around the map that you could swoop down and pick up.  I even started implementing a system that would allow players to write custom messages on the banners, but today I figured I should actually get a banner towable before I waste too much time on that.


After just a few minutes of work reconfiguring some aerodynamic components and setting up joints, I had something that works... sometimes.  I have worked with ropes in Unity before (see Hoist and Bucket) by chaining small rigidbodies linked together with configurable joints.  This works well under the right conditions, but has a problem with stretching.  Even worse, if it stretches too far, things start to explode.  In Bucket and Hoist, I was able to mostly avoid these problems.  With the banners in When Pigs Fly, however, the forces are much greater and sometimes very abrupt (picking up the banner).  As you can see, I don't have it working 100% yet:

There is another problem that I haven't fully wrapped my head around yet.  Every now and then the banner will sort of lock up in a curve.  This curve causes it to generate lift, which causes it to start swing back and forth, then start spinning.  It will continue to oscillate more and more until it eventually rips the back of the plane off.  I haven't figured out yet if the curve is caused by my aerodynamics code or a problem with the joints.

Little experiments like this are crucial to keeping me excited and interested in a project. This is a low-priority feature that won't make it into the 0.3 update, but seeing them sort of working has inspired me to add them to the official 'to-implement' list.  

When Pigs Fly update 0.2.1 - Critical bug fix and new parts

This morning I discovered a critical bug in When Pigs Fly that was causing aerodynamic forces on some objects to be calculated incorrectly.  I have updated the game to 0.2.1, which includes a fix for this bug.  You'll likely notice your aircraft generating more lift and more drag.  In some cases, you may need to add more engines to counteract this drag.

I also included the new parachute and flywheel parts as a bonus.  Get the update here.