Implementing Realm Switching

blog1pic1

The Human Realm, although there are no humans here yet.

What?

The core mechanic of Spirits of The Shogun is that the player can switch between realms to defeat one type of otherwise invincible enemies at a time.
There are two different realms and each realm have two distinct types of enemies. The Human Realm have human enemies and The Spirit Realm have demon enemies.
The player is present in only one of the realms but has the ability to switch to the other. The player can only hit and defeat those enemies whom are present in the same realm as the player.
However, the enemies can harm the player from both ends of the realms.

How?

By the time I came to start implementing the realm switching mechanic, I had already figured out a pretty simple solution to it.
All that was needed was a few variables being checked if they’re equal against each other, and if they are then execute something.

I began with creating a variable inside a script on the scene, which would be easily reached by all other scripts. This variable was a boolean (can only be ‘true’ or ‘false’) named m_spirit, and would tell what realm the player was in.
Then, each type of enemies would have their own boolean variables, also called m_spirit, being set to true if they were demon enemies or vice versa.

The projectiles and the melee hitbox the player attacks with possesses also a m_spirit variable. The variables gets assigned to a value equal to the global m_spirit variable, when the objects of those variables have been instantiated.

Now, whenever the player attacks and it hits, the code checks if the spirit variables of the attack and enemy are equal. If they are, then they are in the same realm and the code for collision behavior can be executed.

I made sure that the spirit variables for the player’s attacks and the enemies were public in the code. That means non-programmers could easily edit the values directly through the Unity Inspector.

Why?

I simply found it as the fastest and easiest solution to have variables being checked if equal to each other. I didn’t want to dwell too much on other options, mostly because I couldn’t come up with anything else on second thoughts.
I could have named the global m_spirit m_globalSpirit, but it was not my biggest concern at the time.

The reason I made the spirit variables public for non-programmers to edit was so they didn’t have to delve into the code to adjust something. It’s even easier for us programmer since it’s faster to edit through the Unity Inspector.

Blog1Pic2.png

The Spirit Realm. The dark purple shaded placeholder demon enemies belongs here.

About Antonio Huayna Ackalin

2016 Programming