I’ve been developing and learning Unity3d quietly in the background for several months. Building prototypes, learning best practices, talking to industry folk, and even teaching a few college artists and coders basic Unity3d workflows.
But I realized I haven’t actually been sharing my discoveries as I build prototypes.
A major learning tool I used within the web industry over the past decade was writing; namely writing about what I was doing to a private community. …
Games have so many moving parts from 3d, animation events, and physics. Not to mention all the code we need to communicate between the different parts and objects.
At this level of complexity, we require ways to handle Dynamic Events between two objects; events such as a sword swing connecting with an enemy, or a player walking close enough for a button prompt to appear. We can not hard-code these setups either as we simply don’t “know” when they will occur.
That’s where GetComponent can come in.
Unity3d has a few tutorials out there but one of my favorites is this official 2013 tutorial which is where the above gif is from. While the exact steps are a little different than what I’ve written below the base is still the same. To recreate the door we’d simply re-use the concepts below but just add a breakable force level to the joints.
Joints are great for breakable panels to rope physics, to bosses that can swing wrecking balls of death, to just Ragdolls.
The simple 101 examples of joint usage we’ll be doing are hanging platforms with interactable…
A lot of people skip Physics Materials when they dive into Unity as frankly, not many tutorials bother explaining the basics and it’s unclear how they work. But once you’ve got the basics down you can do whole game mechanics with them.
Physics materials are essentially settings we can apply to our colliders to create controllable friction and bounciness to simulate life a little bit better.
A good use case example would be Ice, you can set friction to zero or near-zero so your physics items would slide around more realistically.
Or like my above example, Bounce pads.
The main reason to use any Physics System is you want to know when two objects hit without doing all the math yourself.
The typical ones to use are boxes, capsules, spheres. Sometimes Terrian, and sometimes Mesh. Mesh can become a performance issue if used willy nilly on large models though, so like discussed in part 1, “Close Enough” is good enough. So you might just put a box or capsule around something instead of a Mesh.
Unity and most modern game engines have a strong base physics system. This base system is great for most games as then you don’t need to license an expensive middleware like the Havok physics engine or code your own.
I bring this up as a lot of junior designers and programmers get scared away from the topic thinking they’re going to need to re-learn years of mathematics.
Physics in games is a deep topic, but unless you are coding a physics engine, you do not heavy math. Your in-game physics will never be 100% scientifically accurate, and that is ok.
Almost every game relies on some sort of behind-the-scenes timer, even if you don’t realize it. So let’s dig into Unity’s Engine on Time and make the most basic timer code with an ability cooldown.
Unity’s own documentation is the best source and their UML diagram shown below details out the full order of the in-engine timer. https://docs.unity3d.com/ScriptReference/Time.html
So let’s go over the basics.
Every frame figure out how long it’s been with Time.deltaTime
Check if deltaTime > maxDeltaTime gives us a way to control “how much” time can pass before we say “Hey freeze up a bit”. This is…
Creating and destroying objects is a fundamental concept in software development, but especially so in Game Development. So let’s run through the basics real quick and then a quick talk on performance.
All you need is one line of code to spawn something in.
Instantiate( gameObject, position, rotation );
What that looks like in the above Gif though is a bit more complex looking.
Some of the most basic player movement is moving off WASD, Arrow Keys, or with a game controller’s Left stick. In Unity3d this is fairly easy but still trips a few people up.
Unity does a lot of the hard work for us, we don’t need to “know” how windows or mac or our phone handles input as Unity has a built-in InputManager. They even give us default input controls to get started.
Simply open “Project Settings > Input Manager” and you can see it has several events already pre-defined including Horizontal and Vertical.
An Austin TX Unity3d Developer with a unique background in marketing, design, & software development leading digital web agencies to success for the past decade