Making my first game – Part 2: Systems

Apart from randomly generated backgrounds the game needed to have some other mechanics to get it going. For me one of the most fun aspects of modern games is physics. This is why I decided to base the game systems on physics traps and simple puzzles, as well as basic combat. In the end two main ideas drove the development:
– physical interactions (traps, combat),
– relevance of game systems

Design philosophy

All game systems had to fulfill some role:

  • Chests and gold. Apart from measuring “score”, gold is a currency for reviving. I do not like the idea of score without additional functionality.
  • Barrels. Used to kill players and NPCs or to protect the player from traps.
  • Chains. Mounting points for hooks which are primary dangers for the player. Introduction of physics based chains allowed me to use the mechanic to create aesthetic elements like physics based plants and lamps.
  • Pictures on the walls. Apart from being aesthetic elements they also serve two major functions. Each collected picture serves as a respawn point and provides a tutorial text for the player.
  • Buttons and triggers. Used to activate/deactivate traps, open chests/doors. The player may switch off a trap, but also switch it on again at a specific time. This would enable the trap’s use against enemy NPCs.

Attack collision

Character controller was very simple and was used, with small alterations, for the AI. It allowed for walking to the left or right, allowed two types of attack (fast and slow) and handled respawn. As the game revolved exclusively around physical interactions, I had to devise a way of detecting hit collision for:
– interacting with objects,
– triggering collisions with weapons,
– triggering traps and collision with traps.

After some deliberation I decided to make separate colliders for different attacks which would move according to the animation states. These attacks would not only have different speed in combat. The collider movement speed and pattern would have impact on objects in the world.

Weapon collider animated in Unity, the basis of the combat system.
Weapon collider is turned off during the game, and is only turned on during specific point of animation, where it starts following the shape of the animation. After movement is completed the collider is turned off again.

Trap collision

To make traps, I also used colliders. However this time I determined the capability for dealing damage by calculating traps’ movement velocity. This way, a slowly rolling barrel or a hanging hook would be harmless. However falling objects would mean serious trouble for players and NPCs. To check what velocity would trigger damage I would first need to know what actual velocity the objects had at a given time. For this purpose I wrote this short script and analyzed the outputs in the console. This way I determined velocity thresholds at which the objects would start dealing damage.

	void FixedUpdate () {
        myVelocity = myRigidbody2D.velocity;
        Debug.Log(myVelocity);
	}

After checking correct velocities, I wrote scripts attached to traps. This means a hook trap would need to have an “x” axis velocity of more than 4. After fulfilling this condition, the trap received a “AttackCollider” tag, just like a player’s or NPC’s attack. Otherwise, it was not harmful:

if (myRigidbody2D.velocity.x > 4f) // the magic number here should have been parameterized
        {
            this.tag = "AttackCollider";
            myBoxCollider2D.enabled = true;
        }   else
        {
            this.tag = "Untagged";
        }

The final effect can be seen on the GIF below.

Physics systems in action.

 

You may also like...

1 Response

  1. March 3, 2019

    […] making my first game I encountered two major problems, which took me quite some time to figure out. Below you will find […]

Leave a Reply

Your email address will not be published. Required fields are marked *

Social media & sharing icons powered by UltimatelySocial