About the author:

All posts by Terence:

Finding which is the shorter 2D angle

Calculating the shorter angle of rotation in 2D

Here’s a really simple math problem in 2D games development that has a surprisingly complex solution. If I were to give you angles a and b, how would you calculate 1) the direction — that is, clockwise being positive; and anti-clockwise being negative — and 2) magnitude of the shorter angle of rotation from a to b?

Main angle question
We want the angle in green.

When you visualise it, both values seem so obvious; which was why I was so surprised I couldn’t figure it out. On the surface, it seems really simple — if you just take b – a, doesn’t it give you the solution?

Continue reading
Static variables explained, in Java

Static variables, explained (using Java)

One of the more complicated concepts that beginning programmers have trouble grasping is static variables. This is in part because static variables work in a way that is quite opposite to how classes and Object-Oriented Programming (OOP) work.

Since examples work wonders in explaining concepts, here’s a use-case in Java that will help to illustrate the concept. Don’t code in Java? No problem. OOP concepts are (mostly) the same across programming languages.

Continue reading
Fixing off-centre Tiles in the Unity Tile Palette

Fixing an off-centre Tile Palette in Unity

When importing Tiles into the Tile Palette in Unity, you may sometimes run into an issue where your Tiles are not aligned with the grids in the Tile Palette, which will subsequently lead to the Tiles being off-alignment with the grid in your Scene too.

Continue reading
Setting up Unity's Device Simulator

Setting up Unity’s Device Simulator

Unity’s Device Simulator is a very nice extension in Unity that allows users to quickly and easily test out their games on a mobile platform. It extends the Game window by adding a dropdown that allows the user to switch between the Game view and a newly-added Simulator view.

Continue reading
Fixing a jittery camera in Unity
Screenshot from Cobalt Blue, a game currently in development.

Fix jittery camera movement in Unity with Rigidbody Interpolate

If you’ve got a player character in your game that derives its movement from a Rigidbody or Rigidbody2D component in Unity, and you write a script to make your camera follow it, you will likely see jittering in your camera movement.

Here’s an example:

Camera jitter in Unity
It’s not very noticeable if you don’t move at high speeds.
Continue reading
Importing CSV files into a MySQL table

Importing a CSV file into an SQL table

CSV stands for Comma-Separated Values, and CSV files are text files that look something like this:


johndoe,john@example.com,"71 Pickering Street, Singapore, Singapore",+65-91234567
janedoe,jane@website.com,"24 Raffles Lane, Singapore, Singapore",+65-81234567
marysmith,mary@smith.com,"83 Riveting Road, Singapore, Singapore",+65-97654321
bobsmith,bob@smith.com,"84 Riveting Road, Singapore, Singapore",+65-87654321

Essentially, the CSV file format is meant to represent tabular data. The above CSV file represents the following table:

johndoejohn@example.com71 Pickering Street, Singapore, Singapore+65-91234567
janedoejane@website.com24 Raffles Lane, Singapore, Singapore+65-81234567
marysmith mary@smith.com 83 Riveting Road, Singapore, Singapore +65-97654321
bobsmith bob@smith.com 84 Riveting Road, Singapore, Singapore +65-87654321

Due to their tabular nature, data in a CSV file can very easily be imported into and stored in an SQL table. The commands to do that, however, are not very well-documented online.

If a CSV file does not open as a text file on your computer, that’s because your computer is opening the file with a spreadsheet program such as Microsoft Excel. In such a case, to see the file as text, you will want to open these files on a text editing software such as Notepad.

Continue reading
Python in XAMPP

Running Python in XAMPP

Are you looking to run Python as a server-side scripting language on your XAMPP installation? Here’s a guide on how to set it up.

Continue reading