Ex-Terminator

Creating Reorderable Lists in the Unity Inspector

Update: Like this article? Then check out this other article on creating a dropdown filter for the Unity Inspector.

Over the last 5 months or so, me and my team have been involved in the development of a hybrid tower defense and RTS game called Ex-Terminator (click on the link to try it out, it’s free!) as part of a school project. During the course of developing the game, we quickly realised that, in order to allow us to have the flexibility to experiment with our level design, we had to experiment with a class in Unity called the ReorderableList.

If you’ve read some of the other articles here, you’d have noticed that we normally link Unity classes to its page on the Unity Scripting Reference. We didn’t do so here because there is no official documentation for it at the time this article was written. The ReorderableList class is filed under the namespace of UnityEditorInternal, which also doesn’t have official documentation. We’ve decided to write an article about it, however, because of how useful it is, and because of how little information there is currently about it online.

Continue reading
Debugging with Beverage

Fixing an Apache cron log rotation error

If you manage a Unix-like server, every now and then, you might get an email from the server notifying you of important errors that occur in your server. Here’s one that I got earlier today from an Ubuntu 18.04 server of mine:

Cron <root@terresquall> test -x /usr/sbin/anacron || ( cd / && run-parts –report /etc/cron.daily )

/etc/cron.daily/logrotate:
error: error running shared postrotate script for ‘/var/log/apache2/*.log ‘
run-parts: /etc/cron.daily/logrotate exited with return code 1

Mail sent at 06:39

It’s never fun to receive server admin emails like this, because it means that your server has issues, but the message tends to be really ambiguous, so it’s really hard to figure out what the issue is. Obviously, I didn’t know what the issues were, so I had to do some research.

Continue reading
Unity Editor Scene view

Checking the type of GameObject you are colliding with in Unity

In any given game, you are probably going to find dozens, if not hundreds of different objects colliding or intersecting with one another. Hence, one of the first things you learn in Unity is how to identify the type of object you have touched. These are the most common ways to do so among beginners:

void OnTriggerEnter(Collider other) {
     // If a GameObject has an "Enemy" tag, remove him. 
    if(other.tag == "Enemy") {
        Destroy(other.gameObject);
    }
}
void OnCollisionEnter(Collision collisionData) {
    // If a GameObject has an "Enemy" tag, remove him.
    if(collisionData.collider.tag == "Enemy") {
        Destroy(other.gameObject);
    }
} 

Essentially, the idea is checking whether the object we are colliding with or touching has been labelled with an Enemy tag, before we perform any action on the object.

Where tags are assigned.
Image source: Unity Manual: Tags

While it is simple and easy-to-understand, there are better ways of identifying objects we are colliding with.

Continue reading

Content begins after the advertisement:


2D vector math hero - polar movement

Vector math for polar movement in 2D games (Unity)

Polar movement, i.e. moving objects at an angle, is something that people starting out in games programming often have trouble with. Coordinate systems are easy to understand, and so is moving things left and right or up and down; but what if you want to move at angles that are not parallel to an axis, like 30° upwards, or towards a target? How do you get a vector that represents that direction of movement?

Continue reading
Emission lighting in Unity

Getting your emission maps to work in Unity

Emission maps (also known as emissive maps) are textures that can be applied to materials to make certain parts of an object emit light (like the cube in the image above). In Unity, lights from emission maps don’t start affecting the scene as soon as you place them on the material. There are a lot of settings you have to get right in your scene and material settings to get the emission maps working right.

Continue reading
Collision Detection Modes in Unity

Collision detection modes in Unity’s Rigidbody component

Update (14 August 2020): Looking for an article on the Interpolate property on Unity Rigidbodies? We’ve put one together recently, so have a look here.

It isn’t particularly difficult to set up physics-based movement for objects in Unity — simply add a Rigidbody component onto an object that has a Collider component, and you’ll have yourself an object that moves and collides realistically with other objects.

Discrete collision
This was set up in 10 minutes.

If you start having fast-moving objects however, you might start to see these objects tunnel through obstacles.

Discrete collision tunnelling
Just like quantum physics. Sort of.
Continue reading

Content begins after the advertisement:


Coding your projectile arc

Coding projectiles for your tower defense game — Part 2

This article is a part of the series:
Coding projectiles for your tower defense

In the second part of this series, we will be exploring how to give our projectiles a nice vertical arc as they travel towards the target. This article will expand upon the work in Part 1, where we coded a projectile that could home in onto the target and detect collision with the target without using Unity’s physics engine’s.

Continue reading
Homing projectiles

Coding projectiles for your tower defense game

This article is a part of the series:
Coding projectiles for your tower defense

If you’re developing a tower defense game, one of the first questions you are going to be dealing with is this: how do you make the projectiles that your towers fire hit their targets? After all, these fired projectiles take time to reach their targets – targets that are constantly moving. Sometimes, by the time a projectile gets to where it was aiming at, their targets would’ve sometimes moved out of the way.

Continue reading