top of page

Updated: Jul 13, 2020


Hi there!

Today I will be featuring part of the script that I will be using for an ongoing project (still in early stages). It is an improved version of a function that I used back in one of my previous projects, Mirage Forest. Here I will be sharing the difficulties and problems I faced in the older version and what I have changed.

Firstly let's look into the hierarchy of the player, the script is located on the Player GameObject (I'll call this as "parent") of the highest hierarchy and has the camera and the character model as the children.

Here are two different clips featuring the effects of the old scripts and the new scripts.

Above: Both models are set to face left and then reset camera is pressed.

Left (Old) : camera turns clockwise, taking the long way around.

Right (New): camera turns counterclockwise, taking the shortest path.

Above: Both models are set to face right and then reset camera is pressed.

Left (Old) : camera turns clockwise as well.

Right (New): camera turns clockwise, taking the shortest path.

Following on, the scripts. Let's look at the old script first.

Old Script

The old script is relatively simple, the parent will turn clockwise on an a certain interval wihile, the character model will turn counter-clockwise countering the parent's movement, and it will continue until the character model's local rotation goes less than or equal to zero.

Problems with this code:

- It only turns clockwise, potentially taking a longer path to rotate as seen the left clip above.

- The angle after it stops is not at zero (It will overshoot by around 8 - 11 degrees).

New Script

As for the new script, I made the variables modelAngle, parentAngle and lerpRate, to reduce the amount of long repetitions of long lines of codes. I also made a change to the if conditions to check for localEularAnlgles rather than the local rotation, as it makes more sense that way since the euler angles is the one being modified. It also makes it a lot easier to use because euler angles only stays within the range of 0 - 360 degrees.

Then, as for the issues above:

- The code has now several conditons to check for the current euler angles of the character model to consider whether to turn clockwise or anticlockwise to take the shortest path.

- The top two conditions on the other hand handles the problem where the angle does not end up at zero, which when the lerping processing reaches less than a 12 degree difference from zero from either direction, it clips right away to zero.

That's for for now, hope to write more about the project soon!

  • Hayashi Tensai
  • Jan 9, 2019

Updated: Jun 10, 2020


This one of the first scripts that I wrote in Unity 3 years ago in our first game project together as a team, it's quite a simple algorithm that controls Ifrit's attack pattern and it is split into 3 phases.

First there is this PhaseController() that takes control which phase to call.

Now's let look into phase 1. In phase 1 if the player stays on one platform for more than 5 seconds Ifrit will start lighting the platform on fire.

In this first part of function, the for loop checks for each and every platform for the player and will continue to lock on the player's position until the player stays on one platform for more than 5 seconds.

Once if goes beyond it stops checking on the player's current position and proceeds to lock on that platform regardless whether the player is there. It then starts a precursor animation to warn the player on the incoming fire.

After the 8th second, the pillar of fire comes up and stays for 3 seconds before setting the timer back to zero and repeating the function loop.

In phase 2, Ifrit remains the fire pillar attack, and adds two more attack types to its attack pattern, the fire meteor and fire wave. Phase 2 starts when Ifrit's health falls below 50%.

In addition with the earlier fire pillar algorithm in phase 1 still running, the PhaseTwo() will randomize one of the two above attack patterns every three seconds.

If the randomization comes out with a value less than or equals to seven (87.5% chance) It will summon a meteor.

If the randomization lands on eight (12.5% chance) then it will summon the fire wave, which as seen above it will execute a list of actions, adding black bars to top and bottom, Initiates the fire wave, force teleporting the player to furthest left platform, and deactivating all teleportation temporarily until the fire wave is destroyed (called by another script).

Last but not least there is phase 3, it triggers when Ifrit losses all its health.

In the last part of PhaseTwo() it has a condition to check if Ifrit's health is at zero, and if the condition holds true, it will update the phaseCounter to 3.

In phase 3, several short sentences will appear and the player will have to finish typing all of it within 35 seconds to clear the stage , if the player fails to do so, it will regain 10% of its health and revert back to phase 2.

Above: the final type sequence of phase 3.

Updated: Jun 10, 2020


In this section I will be featuring the AI Systems for the rabbits in the game. Firstly, all three rabbits share the same AI script, differentiating them by using an enum:

This script is then split into two parts, the movement and attack:

Movement

It's a simple algorithm that moves the rabbit left and right, except the carrot rabbit, that one stays stationary.

Attack

This part is the algorithm where the normal rabbit chases the player when the left or right raycast hits the player and​ activates the invisible hit box when they are in range of the player.

As for the carrot rabbit, there is two conditions as you can see, checking the booleans, "leftAttack" and "rightAttack", these are turned true when the player is its respective direction, and it will shoot the carrot to the direction of the player. Else, it would shoot the carrot at a random direction either left or right.

The last condition at the bottom is for the normal rabbit and the big rabbit, where isHit is true (isHit checks for collision of the attack hit box with the player), it will damage the player on an interval until the player leaves the hitBox.

akarin_box.png

Moved to a new site!

You will be redirected to the new site in a moment, if nothing happens after a while manually type in the url tensaiscorner.com to visit the new site!

© 2017 - 2020 Hayashi Tensai

bottom of page