Recent Blog Posts

Why MiniScript?

Joe Strout —

As more and more people discover MiniScript, the question is occasionally asked: why? Why was MiniScript created, and why should someone use it rather than some other language?

It's a perfectly valid question, so in this post I will try to clarify. My purpose is not to convince anyone of anything, but to explain why, after years of using other scripting languages, I felt compelled to create something new. I'll do this without attacking other languages, since every language has its fans and I don't want to kick anybody's dog; instead I'll focus on what I think is really cool about MiniScript, and how it offers a collection of advantages that, taken together, can't be found anywhere else.

read full post

MiniScript Goes Open-Source

Joe Strout —

MiniScript has been available as a Unity plugin since 2017. But it has been such a success with its users that it deserved wider distribution. MiniScript in Unreal games, MiniScript on the command line, MiniScript in your browser... why not? And while it was great to get a little financial support for working on MiniScript in the early days, in the long run keeping it commercial only slows down its adoption. That's why, as of today, MiniScript is open-source.

read full post

Getting Started with the Oculus Platform SDK

Joe Strout —

I've been doing a lot of development for the Oculus Go lately, which is an absolutely marvelous VR platform — inexpensive, easy to use, and high quality (when the development is done right). For the most part, developing for it in Unity is straightforward; the camera automatically tracks the rotation of the headset, and the OVRInput class provides controller tracking and touch/button inputs.

But at some point you may need to use some part of the extensive "Oculus Platform" SDK. This provides information about the current user, such as their Oculus username, and also provides all manner of match-making and social services, including efficient voice (VoIP) chat. Unfortunately, accessing this SDK isn't nearly as simple as you might expect. This post explains how to do it.

read full post

How a Daily Purge Folder Changed My Life

Joe Strout —

I used to be just like you. I had a Downloads folder full of junk, and a desktop full of clutter. Screen shots, temp files, email attachments, and more filled my computer like leaves on the ground in autumn. Now and then I would try to clean up the mess, but it was a chore that all too often went undone.

Then I made a DailyPurge folder, and my whole life changed.

read full post

Configurable Input in Unity

Joe Strout —

I have long thought that Unity did not really support configurable input out of the box — at least not without using the ugly default Graphics/Input configuration dialog (which no polished game would ever inflict on its players). Particularly if you wanted to support hot-swappable joysticks or gamepads, I always believed you had to use some third-party plug-in.

But I recently discovered that this is not true! Making configurable, hot-swappable input in Unity can be done without any plug-ins, and it's not even all that difficult. Read on to see how.

read full post

Fading the Music on a Scene Change

Joe Strout —

A lot of games in Unity are organized into several scenes, most notably a title scene and a play scene.  If your game has background music, you're likely to want different background music for each scene.

Just sticking a music clip on an AudioSource in the scene would accomplish that, but the music would cut off abruptly when you change scenes, which is jarring and unprofessional.  Much better to fade it out over several seconds.  That requires not letting the object be destroyed when the scene changes, and handling the scene-change event — which thanks to recent changes in the Unity API, is not as easy as it used to be.

read full post

Arcing Projectiles in Unity

Joe Strout —

A frequently asked question in both the Unity forums and on Unity Answers is: How do I make a projectile arc to its target, like an arrow shot from a bow?  I've seen (and given) lots of different answers to this question, and honestly, most of them are unjustified hacks.

The right (and easy!) way to do this is: just add a bit of arc to your standard movement.  Objects in freefall (ignoring air resistance) follow a parabolic arc, and the equation for a parabola is very simple.  So, we can just use that equation to compute how must extra height we should have, and simply add it to our Y position, and the job is done.

read full post

Implementing Cheat Codes

Joe Strout —

Cheat codes are secret ways to alter the functionality of a game.  It's a term that makes me cringe as a parent, since we teach our kids never to cheat — but once a game starts to grow complex, cheat codes are absolutely essential testing tools.  They let you bypass minutes or hours of gameplay you already know is working, in order to get to the part you're trying to fix.

So, how do you actually implement them?  This post explains how we do it in our Unity games.

read full post

Use a PID loop to control Unity game objects

Joe Strout —

One of the most general and common tricks ever to come out of industrial control theory is the proportional–integral–derivative controller (PID controller), sometimes known as a "PID loop."  It is a simple equation that you can use to control any one-dimensional variable, such as a throttle, a motorized hinge, etc.  All it needs for an input is an "error" signal — that is, a measure of how far off something is from where you want it to be, plus three constants.  Most importantly, it does not need any model of how the value it's controlling relates to the output.

In this post, I'll give you well-encapsulated code for a PID controller in C#, and show how to use this in Unity to control the throttle of a hovercar.  The hovercar physics involves momentum, drag, and controls that don't respond instantly, just like a real hovercar!  But the PID controller doesn't care about any of that; once you have the three constants tuned, and hook up the error signal (in this case, the difference between the current altitude and the altitude you want), it does the rest.

read full post

CallLater: deferred callbacks for Unity

Joe Strout —

In many game projects, I've often found the need to execute some bit of code at a later time.  Often this relates to audiovisual flourishes.  For example, when the player does something scoreworthy, we may want to start a particle effect and sound right away, but then spawn a different effect after a short delay, and actually update the score a while after that.

You could certainly spread the code to do those things out into different classes or methods, triggered by events or other custom code.  I've certainly been known to do that; I love Unity Event, and most of my classes that do anything over time expose events for when they start and finish their work, making it easy to chain them together.

But sometimes, dividing up the logic that way makes the code less clear, not more.  There may be one place in the code that is handling everything related to this set of actions, and the only thing driving the code apart is that you want it to happen at different times.

CallLater was created to handle just this situation.  It lets you write some code, right there in the middle of a method, to actually be run later, after whatever delay you specify.

read full post
 

All blog posts