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:
Ever thought about why a menu only opens up if you press the, let’s say, ESC key on your keyboard? Or the menu button on your controller?
Why does the player only attack when you press X on your controller and only jumps when you press the A button on it?
All of these things are conditions. If the player presses the A button, then DoJump().
Noticed the method I used here? That’s what’s going on inside script. It checks for input on the key you want and if it is detected, it will then do some logic.
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…
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.
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…
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…
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² =…
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.
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?
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!
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 :)