Practice with Unity

Practice with Unity

https://t.me/game_development

Before creation your first game, you have to play with Unity, understand what is this, create something. This important, because you will understand a fundamentals of Unity Interface. 

Unity Download

You can simply download Unity from their official site https://store.unity.com/download?ref=personal

After download open Unity

Then click in right upper corner New+, and tick the assets packages and scripts that we need. We will need:

Character Controller

Particles

Physic materials

Scripts

Skyboxes

Terrain Assets

Note: if you haven't this assets you can simply download them them from unity asset store lately.
Just type what you need in searchbar


Give a name for your game, choose 3d, location and press Create project.

It can take a few minutes for importing all assets.

In Unity

When importing had finished you will see this window:

The first thing you may want to do is customize the layout. Every window can be clicked and dragged into position. Alternatively, you can use the default layouts provided with Unity by clicking the drop bar under Layout in the top left of the screen. I like the Tall layout, though I find it helpful to put the Game view below the Scene view.

There are five main windows that you are using most of the time with Unity. They are the Scene, Game, Hierarchy, Project, and Inspector windows.

Scene – this is where the game making happens. It shows what elements you have in your game and where they are relative to each other. There is a block in the upper right corner showing the spatial orientation of the scene.

Game – shows the view that the main camera sees when the game is playing. You can test out your game in this window by clicking the Play button in the top, center of the screen.

Hierarchy – lists all elements you have added to the scene. This is the main camera by default. You can create new elements by clicking Create and selecting the type of object you want. This can also be done by using the GameObject dropdown menu at the top of the screen.

Project – shows the files being used for the game. You can create folders, scripts, etc. by clicking Create under the Project window.

Inspector – this is where you customize aspects of each element that is in the scene. Just select an object in the Hierarchy window or double-click on an object in the Scene window to show its attributes in the Inspector panel.

Lets look what we have on default scene, not so much, isnt it ? Object with name MainCamera, by clicking on the name of which in the hierarchy we see a cone of viewport and a small window with a view from the camera.

The Main Controls of the editing window:

middle mouse - moving the camera left and right (along the internal plane xy)

left click - understandably, the selection of the object (although it is hard to switch between Blender and Unity :))

Right click - rotation "head"

F - centering on the selected object

Dragging an object with a pressed ctrl - dragging in steps of 1 unit of coordinates

By the way about the coordinates - the developers advise to take 1 unit of game space for 1 real meter, and it is better to stick to it (at least to do less with physics).


Terra Nova

Let's create a surface on which we will walk.We do not have models, so we might create just a big plane ... But we'll create a land, I mean Terrain - it's a better then simple plane. To do this, select Terrain-> Create Terrain from the menu. Well done!

Again, not very impressive. First, change the size of the terrain through Terrain-> Set Resolution. By default, the Length and Width parameters are 2000, i.e. 2 km to 2 km. For simple games, we do not need that much, 500 and 500 - more than enough.


Now assign a texture to the ground. To do this, select terrain (in the main window or in the hierarchy), after this we can see the available properties in the object inspector. There we might see tools for editing terraines (standard - raise / lower, smooth, etc.). You can immediately begin to draw the landscape you want, but at the moment we are interested in a button with a brush "Paint the terrain texture". And on the tab that it opens, the Edit textures button, in the menu of which we click Add Texture:

A window opens with the parameters of the future texture. We find one of them with the value "None (Texture 2d)" and click on the ball with a dot to the right of these words. The selection of the texture from the project already added to the resources will open. By the way, to add a texture to the project, it's enough to just copy it to the project folder - the Unity will pick up everything. The import of everything else happens annalogicaly and the deletion of the resource from the project means physical removal from the disk.

Select the desired texture, for example Grass (Hill). You can add a few more textures, for example Cliff (Layered Rock), and using a brush selected a little higher, paint on your own. At me after the previous manipulations it turned out here so:

If we at the moment press the "Play" button at the top of the screen, you will most likely see a piece of our poorly lit ground on a blue background. But since it is not interesting, so before we continue, we need to add to the scene the lighting that simulates the Sun, and replace the blue background with sky. Light is added through the main menu, GameObject-> Create other-> Directional light. Then, following the picture, we press the button which changes the arrow-helpers around the selected object on the axis of rotation. Draging these axes, we, oddly enough, rotate the directional light so that the earth is painted more colorfully.

For the sky instead of the blue canvas above the head, you need to specify the skybox texture. To do this, go to the menu Edit-> Render Settings, find the property "Skybox material" and, as we did with the texture of the earth, click on the circle with a point to the right of it. We will be shown materials available in the project. Choose any with the word skybox, for example sunny2 skybox. Great, now our test ground looks livelier.

Control and camera

First, create an object for the player. Rather, not to produce unnecessary scripts, we will rename "Main Camera" to "player". Now, selecting the camera, in the menu, select Component-> Physics-> Character Controller. Character controller is a component that handles the position of an object (or rather, a character) in space: its movement, turns, falls, jumps and collisions with other objects. All this can be done directly, without the help of this wrapper around the standard functions of moving objects and checking collisions, but then the implementation code of the movement grows many times, which is bad for the first acquaintance with the engine. And so, in general, you can in the first lesson not coding :)

Note
Any object that we see on the stage is an instance of the class with the talking name GameObject. He has some number of so-called components - which in turn, are instances of their classes. Each component performs a certain utilitarian function. So, every GameObject should have a Transform component, which deals with storing the current coordinates, the rotation angle and the dimensions of the object in three-dimensional space. And, at the same time contains methods for performing actions on the position of the object in this space: moving, turning, etc., i.e. when we drag the object in the editor, we change the coordinates of its Transform.
But for example, the component RigidBody deals with processes the physical behavior of the object: all that we see when the barrel from the shot falls on its side - is the result of the work of RigidBody. Which, by the way, will not be able to work properly unless you assign to object, component of a Collider type , which stores a three-dimensional model, which defines the collisions of the object.

Around the camera, we now see the green lines forming the capsule, on which the collision with the player is calculated - his body, so to speak. The camera is in the middle of this capsule, but we do not need eyes on the belt (although the situation is different :)), so we need to move the camera to the area of ​​the alleged head of the character. But this capsule is a part of an object with a single Transform, and therefore it will not be possible to move it apart from the camera. Fortunately, if we look at the properties available on the Character Controller in the object inspector, we'll see the Center property there, with the parameters x, y, z. That is, we can move the center of the capsule relative to the center of the object. Set y = -0.8 and get the normal height of the eyes.

If we now put our player above the ground and turn Play on, our camera will still standing. This is because Character Controller only processes incoming control commands, it does not show initiative. To explain to her what to do, drag-n-drop on the player a script, which lies in the prefabs inspector in the folder Standard Assets \ Character Controllers \ Sources \ Scripts and is called "CharacterMotor". Its task - using the methods of Character Controller to implement the basics of movement: to realize the action of gravity, jumps, calculate the current speed and direction of movement. Running the level will now cause the player's camera to fall to the ground - already something.

But we still standing at the same point: after all, we do not have a script that reads keystrokes and sends them in CharacterMotor. This is done by the FPSInputController script in the same folder. We drop it on the player, run and cheers - the buttons W, S, A, D now allow you to walk, and the spacebar - to jump! But we are looking in same direction. To rotate your head and go where your eyes are looking, you'll need one more script, from folder where we get CharacterMotor: MouseLook. We drop it, and press Play - and we receive high-grade controller.

Fin

I hope that I described in sufficient detail what needed to be covered, and did not focus on unimportant little things. I would like to believe that it will be really useful to someone. I'm waiting for rational criticism and wishes for the next issue. Thank you for attention! Contact @Longlife_Games

Report Page