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


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.

Parachutes and Catapults

People have been asking for parachutes since the original game jam version of When Pigs Fly.  I teased chutes with the parachickens in v0.2, but now I'm adding them for real in v0.3.  Since the first post-jam update, I've been keeping the code behind When Pigs Fly as modular as possible.  This allowed me to re-use the parachute code from the parachickens.  The implementation is very simple, but it seems to work pretty well.

When the player presses the key to deploy the chute, it starts this coroutine:

IEnumerator UpdateChute()
{
    float t = 0f;
    while(t < deploymentDelay)
    {
        t += Time.deltaTime;
        yield return null;
    }

    parachuteModel.gameObject.SetActive(true);

    t = 0f;
    while(t < deploymentTime)
    {
        parachuteModel.localScale = Vector3.Lerp(Vector3.zero, maxParachuteScale, t / deploymentTime);
        rigidbody.drag = Mathf.Lerp(0f, parachuteDrag, t / deploymentTime);
        parachuteModel.LookAt(transform.position - rigidbody.velocity);
        t += Time.deltaTime;
        yield return null;
    }

    parachuteModel.localScale = maxParachuteScale;
    rigidbody.drag = parachuteDrag;

    while(rigidbody.velocity.magnitude > 0.5f)
    {
        parachuteModel.LookAt(transform.position - rigidbody.velocity);
        yield return null;
    }

    parachuteModel.gameObject.SetActive(false);
}
All the parachute does is raise the rigidbody's drag value.  Then, every frame, the parachute model is rotated to look along the negative velocity vector of the rigidbody.  The parachute starts doing weird things once the pig hits the ground and stops, so I simply disable the model once the magnitude of the velocity is below a certain threshold.  

I needed a quick way to get the pig up to altitude to test the new chutes.  Sure, I could just change the spawn point to a higher point, but where's the fun in that?  Instead, I built this pig catapult thing.  The first few iterations spun themselves apart, and I ended up having to up the break force on the joints (cheating).  I want players to be able to build crazy stuff like this, so it looks like I'm going to have to add some stronger structural parts in the future.