Keep the Inspector tidy!

You might have noticed me using the [Header] Attribute in some of the previous articles (like this one).
In this short article, I’d like to show you what this attribute actually does and why you should use it. Let’s get started!

Let’s take the Player.cs script as an example. To make it easier, I will just use the variables with a [SerializeField] before them, so we just have those that we actually see in the Inspector. We currently have the following variables matching these filters:

In the Inspector, those look like this:

Moving in a circle does not have to be coded, ya know?

We already created a circular movement behavior with the help of math. But you know what? I don’t like math… Like, at all. And hey, it’s okay to hate it, even as a game developer where you need it sometimes. Anyways, let’s create a circular movement today without using math or code at all!

I. The objective
The objective is pretty clear. We shall create a circular movement without using code or math but with the help of the Animator.

II. Creating the actual behavior
We don’t need assets for this animation. We can simply manipulate the position of an GameObject…

Hmm… Which enemy will be the right one to destroy?

Photo by GR Stocks on Unsplash

There might be some time when you develop a game where you need to calculate the closest enemy out of all on the screen. Let that be because you want to implement a powerup which targets the nearest enemy or have another idea why you want to do that. Let’s figure out how to do that in todays article!

I. The objective
We have a player and two enemies on the screen. As we only want to target the closest enemy, we need to calculate the closest one. The chosen enemy shall be printed out into the console.

II. Theory…

Wanna play cat and mouse?

Another horrible pun to start the article. Nice!

Anyways, you might have played some games where some objects are always looking at the mouse pointer. This can be used for various reasons actually. Just for fun, for making the background details even more detailed, to horrify the player by constantly looking at his cursor, to make point-and-click games more detailed, …

There really are many use-cases for that. Let’s implement that today. You will be surprised, but we already know the basics of doing that. Remember yesterdays article?

I. The objective
Todays objective is that the capsule will keep track of…

Around the corner? Wait, which angle do I need to target you?!

Angles are used quite often in video games. We talked about rotation before, and angles are a perfect combination here! As you change your direction, you might have another angle to the GameObject looking at you. To keep track of you, it needs to calculate the angle it has to look at you. Let’s take on how to implement this behavior today!

I. What the objective?
The objective is to let the Capsule “point” towards the player cube.

II. The mathematical aspect
We need some math functions to calculate the angle. We already have two sides given on the triangle. The…

Player. Where are you? I need some fresh flesh…

Okay, no worries. We have a screen between us, so nothing will happen to you ;-)

Anyways. You might have played some games before in which enemies are chasing you. Take Minecraft as an example. Remember the zombies chasing you at night? Or, to turn the paper around, games allowing you to use a magnet to get coins in an easy way. How does that work?

Let’s get started by a little theory first.

A chasing enemy always knows your location and the shortest way to reach you, the distance to you.

Remember the following formula? a² + b² =…

Keep an eye on a GameObject with LookRotation!

You might have played a Tower Defense game before. Have you ever noticed that at least one enemy is always looking at you, regardless where you move to? Exactly that is the concept of LookRotation in Unity. It keeps track of another GameObject and rotates to always focus it. Let’s find out how we can implement such a behavior in Unity today!

The starting environment
We have two cubes, cube A and cube B.

The objective is that cube B will track and follow the movement of cube A.

The code we need
A quick google search will take us to…

Moving in straight lines? - BORING!

Photo by Matt Seymour on Unsplash

Movement in games is exciting. No, really. I’m not kidding. It just a question of how you let the player (or the enemy) move. Let’s say you have an enemy which randomly decides to approach you in a circular way instead of in a straight line. Exciting, huh?

Now then, how can we achieve something like that? The answer is with math! The one subject at school probably nobody liked... But no worries, we won’t need any complicated stuff, just the sin and cos graphs and functions.

Let’s get started!


I. What even is a sin wave?

Fall down with your own gravity style!

Photo by Joanna Nix-Walkup on Unsplash

Ever played a game with a trap door which let’s you conveniently fall down and you can’t do anything about it? Lucky you, then!

Today’s challenge is kind of the same. Let’s take a look at it!

Hey, script B! I need some things from you…

Photo by Volodymyr Hryshchenko on Unsplash

Whenever you will develop something with Unity (or any other game engine) you probably won’t ever get around script communication. Not even if you just want to show some UI elements like the current player lives or the score. Those pieces of information are usually stored inside another script.

That’s what todays challenge is all about. Let’s take a look at it!

Timo Schmid

The mission? Becoming a game developer! RPG is the dream! Writing down my journey here for me and for everyone interested. Thanks for showing interest :)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store