Robots in Unity

Introduction

In this last practice of the Media for Video Games subject we must make a pseudo-fighting game with the characters we have made during the course.

Desarrollo

My intention is to make a very simple simulation of the video game Pacific Rim: The Game in 2.5D (that is, with the characters moving only in the Y and X axis even if it is in a 3D environment).

I have recreated an environment by importing different free assets from the Store (links in the references section), recreating a post-apocalyptic world with sunken cities in the ocean as a background. I have also included a night sky skybox to give more realism and a dark environment.

I have included the “Animation Rigging” and “Cinemachine” packages to better control the movements of the characters and the tracking of the camera.

To start with the programming and animations, I added physics components to all the elements. The robot has a RigidBody with a Capsule Collider and, on the other hand, the floor has a Box Collider. Important to block the rotation and movement of the Z axis of the rigid body with constraints.

I have been writing and improving the robot player script with ChatGPT. Basically, it consists of a state machine that transitions according to key input and calls the appropriate animations according to each state. This approach will allow me to add the game logic simply afterwards.

I created this animator controller where the default animation is Idle. This can transition bidirectionally with Walking depending on the speed parameter. Afterwards the rest of the animations can start from any state and when finished return to Idle (except Defeat, which ends the state machine).  CORRECTION:  the transition to exit must be removed, otherwise the Defeat animation stays in Loop when defeated.

The first “problem” I encountered was that the animations did not transition unless I had finished the clip. Fortunately, this has an easy fix: you only need to uncheck the “Has Exit Time” box in the transition of the corresponding animations.

Something similar happened when a key was held down, since the animation was constantly restarted. I was able to solve this by code making it impossible to transition between states until the attack or defense animations have finished.

I have written in code that when the character walks in the opposite direction to the one he started, the animation is reversed (from speed 1 to speed -1) so that it has the effect of walking backwards with the WalkingSpeed ​​parameter.

When applying what was done in the V1 to the V2 I have encountered some other inconvenience. First, the Walking animation for some reason was exported with 40 frozen frames so I had to cut it. Fortunately, from the Unity inspector this can easily be done. With this robot, it doesn’t feel so good to reverse the animation to make it walk backwards, but all the parameters are correct, so it must be an artistic problem from the previous practice.  CORRECTION:  it turns out that the problem is that when turning the robot, the leg that starts to walk should be reversed. In other words, flipping the character has solved it.

I have added two invisible barriers on the sides so that the characters cannot leave the camera. Finally I have not used Cinemachine to track the characters.

At this point I added two BoxCollider as Trigger in front of the robots to activate the fist area when the animation is executed. I have also made them have a life indicator (100 points) and that if they are defending themselves they cannot suffer damage. As an extra, I added a particle system that throws sparks when they hit to give more feedback. To put it in writing, this game does not pretend to be balanced or to give a fair combat experience.

For the SFX I used several PixaBay audios and played them at specific moments in the script. The SFX that are reproduced are: Attack, Defeat, Impact and Walking.

For the logic of the menu I created a GameManager with an FSM for the different states of the game: GameStart, GameRunning, GamePaused, GameWinnerV1, GameWinnerV2. The menus are gameObjects with buttons, since it seemed much easier to do so than creating a new scene for the main menu, etc. I have also made it play music in a loop and some effects to start and finish the game.

Finally, to export with WebGL I installed the WebGL publisher package and created a local build for debuggear. At the beginning the Vrbn Studios store asset gave me some problems, but I removed all the related scripts from the project (since they provided functionality that I didn’t need for the buildings). In this way it was already compiling (with several warnings in the console, but they are unforgivable).

Now comes the moment I dreaded the most, which is that the project seems to be too big to be exported in WebGL. After an afternoon of trial and error, I managed to export it correctly by importing all the parts of the project one at a time into a previous version of Unity and compressing the files. Even so, the buildings continued to give problems, so he opted for the quick way: make a pre-rendered one and put it as a flat texture in the background. This method is very effective in terms of performance, and more so for a web version. In addition, with the blur effects and others it is not so noticeable. I should have thought about using it before, really.

Buildings with Alpha channel applied.

Final result exported with WebGL Publisher.

WebGL game

Mecha Battle! – Unity Play

Note: I tried to embed the project with an iframe from both Itch.io and Unity Play, but this service’s WordPress does not allow it.

The repository of the whole project can be found publicly in GitLab: https://gitlab.com/jongompal/r5-mecha-battle.git

Vision of the future

The truth is that the result is simple, but I am very happy with the final packaging and how the models integrate with the environment. Obviously, it could be expanded much more with more animations, characters, environments, more types of attack and make a more attractive combat system.

The truth is that I was very attracted to the idea of ​​making a more strategic and slow combat instead of one in which every millisecond counts and fast reflexes are the jewel in the crown. I think that it is an unexplored perspective of the genre and that it combines very well with the aesthetics of Mechas that I wanted to transmit.

In the hypothetical case that I was in the future betting on this concept, I would clearly do a total redesign, thinking a lot more about the mechanics and recreating the artistic section accordingly (although it wouldn’t have been bad to investigate the reverse path for once).

To finish, say that the point that fails me are still the animations. They are the section that clearly requires more work and that is more unnatural. Therefore, in a future project of this style I would look for ways to further integrate the engine’s tools with external ones and even investigate whether it would be possible to create procedural animations that adapt to the environment.

References

es_ESSpanish