Project Update #4

--Originally published at Orientierteprogrammierungobjekteundetwasmehr

So we’ve finished the tutorials and we will start creating our own game.

As a reminder, our objective in the course is to explore and learn about the Unity engine, game logic and how game objects work.

In the last couple of days we implemented a system to create different tanks in the same scene, the logic to control the game flow and audio mixers.

The tank manager is a script that controls that instantiate a tank in the scene, setting its new color, and defines several methods to modify the behaviour of the tank, like disabling control.Project Update #4

The Game Manager is a script that controls the game (duh), setting the targets for the camera (because there could be different number of tanks), and have different functions that are executed based in the current state of the game (i.e.: starting a round, playing, finishing). We can archive this thanks to coroutines, which are functions that can pause its execution and return to the normal flow of unity (updating the frame, etc.) and then continue executing where it left.Project Update #4

So the Game Manager just defines the number of rounds to win, the delay time to start (a countdown), controls the targets of the camera, instantiates the tanks and the Manager also keeps track of the state of the tanks (to finish the game when there is only one tank left in the scene).

Project Update #4

The starting delay just shows the text “tanks!”.

Project Update #4

The audio mixer is just like a filter to all the audio sources that the game have, you can just create one in the project folder.Project Update #4

You can also create sub-mixers, so you can divide the sounds of the game and apply different filters to it, in addition to the main mixer.

Project Update #4

In the output field of the audio source of the different objects you can select the audio mixer that you want that sound belong to.

Project Update #4

And as you can see in the images you can add filters, modify the pitch, level, attenuation and other things until you are satisfied with the sound effects of the game.

Project Update #4 Project Update #4 Project Update #4

The next idea is to create an interface to interact with the tank and game manager scripts. This interface will let the player to set some properties for the game (like adjusting the damage, the force and the color of the tank).


Project Update #4

Project Update #3

--Originally published at Orientierteprogrammierungobjekteundetwasmehr

We are almost on the end of the tutorials, I guess we will finish it and start creating the modified game by Wednesday. Because there are a lot of things we’ve done and there is no much time to explain everything, I’ll just add some images and briefly explain what they are.

This part is about creating the tank health, UI and logic. So I started adding a slider. Because the canvas is it’s own space it’s needed to change the Render mode to World Space.

Project Update #3

I moved the slider under the tank, changed its size and deleted the thing to move its value.

Project Update #3

I changed the default image by this one, it is a circle with a gap in the middle. Also changed the slider mode to radial (so it fills clockwise and not left to right).Project Update #3

I added the script to control the health slider, I used color interpolation to calculate the color needed in the cicle and set the value of the slider based in the health of the tank.

Project Update #3

And now you can see that the tank has a green circle around it. There’s also a explosion animation for the tank, when the healh of the tank reaches zero, an explosion animation is created in the same position as the tank and the tank object is deleted from the scene.

Project Update #3This part is about creating the shells prefabs.

First I added the shell model to the scene, added a Capsule collider to it, checked Is Trigger (to trigger a method when it collides with a tank), and also a light.

Project Update #3

Here’s some code that goes in the Shell. When it collides it searches for tanks (that are in a special layer that groups all the tanks), calculates its distance to the tanks and apply a force and a damage to the tank according to that distance. When the shell touches something, it plays an explosion animation and deletes the shell object. Also, the shell is automatically deleted after it’s been two seconds in the scene (to avoid having around shells that, for some reason, never collided).

Project Update #3

Here you can see, I dropped a shell in the scene, it exploded and the tank taked damage.Project Update #3Next part is about shooting shells, I added another slider, changed the image to the yellow arrow and set its position in front of the tank.

Project Update #3

Here’s the code that allows the tank to shoot. The tank can charge its shoot and when the player releases the shoot key, a new instance of the shell prefab is created, and its velocity and direction is calculated according to the tank position, rotation and the amount of time that the player pressed the key. It also sets the value of the slider to the value of the charge amount, so the player can see the arrow growing when they press the fire button.Project Update #3

And here you can see the tank rotating and firing shells!Project Update #3

Next in the list is creating a manager to handle the spawning of tanks.


Project Update #3

Project update #01

--Originally published at Blog

the team members are:

  • Hermes Espínola González
  • José Andrés Choza
  • Juan Salvador Fernández
  • Gerardo Cruz

The idea of the project is create a video game where the objective is fight in an arena.
Due to the fact that we don’t know anything about 3D modeling and animation, we will use creative commons assets from the unity asset store.
We have already implemented the movement of the character.

Project update #01

For the artificial intelligence we will be using a plugin for unity called RAIN. We are reading the documentation and trying to create our first AI character.


Project update #01

Unity Tutorial – Basic Stuff

--Originally published at Blog

In this post I’ll show the most basic usage of the Unity3d game engine, using the C# programming language, its syntax is very similar to Java.

I’ll be using public domain assets that I downloaded here.

And instead of using the default cube of Unity, I’ll use this one, because it’s made out of Quads (like a plane, you can only see it from one side), and it’s easier to add the textures to it (I don’t know how to use blender and stuff).

Ok, so now open Unity (which you can download from it’s page), and create a new 3D project, by default, it only has a camera.

So, the Editor has windows, and you can move them around, you can add new ones in the Window top menu. The ones I’ll need are Game (here you see what the cameras are projecting), the Scene (where you edit the game), the Inspector (where you see the selected object’s properties), the Hierarchy (where you see and select objects in you scene), the Project (like a file manager), and the Console (here you see errors and warnings).

In the Project and Hierarchy windows, there is a drop-down button that reads: “create”. when you click it, you will see a lot of pre-build thing that you can use in the editor, and whatever you crete, it will appear inside the window where you clicked “create”. When I say “create something in bla”, I mean that you should click “the” bla button in this drop-down, inside the “something” window.

Unity Tutorial – Basic Stuff

Extract the and drag and drop the PNG folder into the Project window. Make sure you organize your files. Create these folders (right-click > create > folder):

Unity Tutorial – Basic Stuff

In the Hierarchy window click on Create > Light > Directional light, this light is behaves like a sun, it doesn’t matter where you put it, only it’s rotation.

Unity Tutorial – Basic StuffPut the Cube.prefab file in the Prefabs folder (does it makes sense?) and then drang and drop that weird thing to the Scene window, you’ll that the cube appears magically in the Scene, and also, the cube is added to the Hierarchy window.Unity Tutorial – Basic Stuff

Open the Tiles folder in the PNG folder, now, if you drag and drop the images in the cube that’s in the scene, you can assign that texture to the side of the cube where you drop the image (and that’s the reason behind the special cube prefab). You can see that, in the Hierarchy, there’s an arrow next to the cube, if you click that arrow, you will see it’s children.

GameObjects can have children, which are also GameObjects. Children have a relative position to it’s parent, and they can be easily referenced from a script. For example, you can have the “player” object, and a “gun” object. You want that gun to be a child of you player, so it’s always, in it’s hand.

Unity Tutorial – Basic Stuff

Now add a RigidBody to the tile, this will allow the tile interact with other objects, and also, deselect the “use gravity” button.

Unity Tutorial – Basic Stuff

Once you’ve done this, go to the Prefabs folder and (in the Project window) click on Create > Prefab. Now, drag and drop the Cube (in the Hirarchy window) to this new Prefab in the Project window. As you can see, the cube is “inside” the prefab. you can now delete the cube from the scene.

A prefab is the way Unity defines custom Game Objects, so that you can instantiate them, without the need to create them again, so it’s very similar to creating a class when you are programming (but of course, it’s not the same).

create an empty game object in the Hierarchy, and name it, I don’t know, map, or terrain, or whatever, then go to the Script folder and create a new C# script, we’ll use this script to automatically generate the terrain, based on the tile I’ve just created, when the game is loaded. drag and drop this new script to the empty game object in the Hierarchy.

Every GameObject you create has different fields, if some field is set to public, it will appear in the Inspector window, you can change the values of these properties inside the Inspector.

Unity Tutorial – Basic Stuff

Everything in Unity is a GameObject, which is a special class of Unity, and every GameObject has at least a Transform. a Transform determines the position and rotation of that object in the scene.

If you double click the script you’ve just created, the code editor should be opened (Visual Studio or Monodevelop).

Unity Tutorial – Basic Stuff

The C# syntax is very similar to Java, but to implement and interface you write <ClassName> : <InterfaceName>.

Monobehaviour is a special interface of Unity, if you delete that, you will not be able to attach the script to a game object.

In Unity Scripts, there are special method names,  the Start method is called when the GameObject is instantiated and the Update is called once every frame. You can search for more special names in the Unity documentation.

add these fields, you want them to be public so you can change them from the Unity editor. the grassTile of type Transform will hold the prefab I created earlier. the tileSize is set to 1 by default, but you can change it from the editor. You need to drag and drop the tile prefab we created to the Grass Tile field that you can see in the Inspector when the Terrain object is selected.

There are Vector2 and Vector3 classes, and they are what you would expect.

Unity Tutorial – Basic Stuff

Now add a Vector2 called terrainSize and these for loops:

Unity Tutorial – Basic Stuff

I’ll create a plain terrain for now, the terrainSize represents the amount of tiles with size = tileSize. These for loops will “walk” through a “grid”, in each position a new tile will be instantiated:

Unity Tutorial – Basic Stuff

This is a static method in the GameObject class that creates the specified object in the scene (and you can instantiate almost anything, because everything is a GameObject). It returns the instantiated object, and we can tell C# to convert it to a Transform (because aTransform is a Game Object, and you know, “polymorphism” stuff).

You can change the values of the public fields that you declarated in the script:

Unity Tutorial – Basic Stuff

You should see something like this in the Scene window.

Unity Tutorial – Basic Stuff


Unity Tutorial – Basic Stuff