UE5 - Create your first game

Article directory

I. Introduction

For those who are new to UE, how to create a small game of your own from 0—>1, UE5 officially provides a great case, as follows: "
Your First Game In Unreal Engine 5" The original text of the video
requires the following materials: :
1. UE5 engine
2. Resources provided by Stack O Bot
3. Read this article patiently (condensed the essence of the whole video)

2. Game display

Please add a picture description

3. Overall Outline

1. Create a project
2. Create the first asset in the game (a small box)
3. Create terrain (terrain tool, switch to terrain mode)
4. Create vegetation (grass, stone) in the terrain and brush it into the scene
5 . Create game controllers including (game mode, player controller, player's pawn)
6. Add animation blueprints to characters to control character actions
7. Create NPCs in the scene, that is, AI (AIController+NavMeshBoundsVolume component)
8. You can add characters The function of "laying eggs" to the bottom of the feet, and adding pathfinding to the position of the egg for AI
9. Enriching the interaction in the scene (button + door)
10. Adding dust effects (special effects) to the movement of characters in the scene
11. Adding to the walking of characters Sound
12. Add shake to the camera when the door opens
13. Game packing

4. Internal implementation

1. Create a project

insert image description here
Please add a picture description
Open the Light Mixer, and add the following lights including "Create Sky Light" to the environment
Please add a picture description
. After the above operations, the scene will change from dark to colorful.
Tips:
Ctrl + l: Rotating the bookmark can Change the direct direction of sunlight (direct light)
Ctrl + space: you can call out the asset panel (very cool)

2. Create the first asset in the game (a small box)

insert image description here
Import the above resources and the corresponding image resources into UE5, there are the following types of resources.
Please add a picture description
Next, assign materials to "M_Metal", "M_Carbon", and "M_Plastic".
Please add a picture description
The above is the most basic, that is, assign a color to The above picture of a material
Please add a picture description
is to assign a texture map to the surface of the material as the basic color, and set the map (normal map) with normal information on the surface of the material to make it concave and convex, and texcoord combines the two pictures Tiling means expansion to make the texture finer and finer. The following two pictures are similar, so I won’t introduce them here.
Please add a picture description
Please add a picture description

If you don’t know much about rendering, you don’t need to study the meaning of the material connection, and you can directly use the simplest method of the first one. After the
Please add a picture description
blessing of the above-mentioned materials, the box will have characteristics such as plastic, cloth, and metal.

3. Create terrain (terrain tool, switch to terrain mode)

UE5 comes with a terrain tool, switch as follows
Please add a picture description
to create the terrain, set the required size and click Create
Please add a picture description
If you can’t see the created terrain, set the display in the scene, check the terrain
Please add a picture description
to create a material and assign it Its material, "My_LandScape_M" as follows, and create two layers are "Grass" and "Sand" and
Please add a picture description
Please add a picture descriptionthen create layer information, as follows So
Please add a picture description
Please add a picture description
far we can draw the site with a brush, as follows, the scene can see two colors
Please add a picture description
Next we To decorate the two environments "desert" and "grassland", you only need to expand the material of the terrain, the principle is the same as other materials. At this time, you
Please add a picture description
Please add a picture description
can see the texture of both the desert and the grassland.

4. Create the vegetation (grass, stone) in the terrain and brush it into the scene

The terrain with only color and texture still lacks a sense of three-dimensionality after all, so we need to add various vegetation to the scene, such as grass, stones, flowers, trees

1. Grass

Create the following plants.
Please add a picture description
Set the grass mesh of the plants created above to the grass we imported. Other parameters such as grass density can be adjusted by yourself. Then set the material
Please add a picture description
of the grass. It should be noted that the blending mode of the grass should be set to "masked" "
Please add a picture description
Pay attention to the two nodes in the lower right corner of the above figure, which are "LandscapeLaerSample" on the left and "LandscapeGrassOutput" on the right. By setting these two nodes, grass can be automatically generated for Grass on the terrain. Finally, we will create it at the beginning" Terrain Grass Type" is set to "LandscapeGrassOutput", the grass can be automatically generated
Please add a picture description
insert image description here

2. Other vegetation

Compared with the grassland, other types of vegetation need to be brushed manually instead of automatically generated. First, we need to create the vegetation

For vegetation with a large number of mesh faces, you need to check and compile Nanite, otherwise it will not be loaded after the vegetation is made. Nanite technology is in the conversion video of Matt Unreal Engine 4->5, and Chris Murphy in the tutorial. Introduction
Please add a picture description
Create a plant.
Please add a picture description
Set the mesh body to the plant like grass.
Please add a picture description
It should be noted that the volume of the rock is large, and unlike grass, no collision body can be added, so we need to set the collision of the rock to "BlockAll"
Please add a picture description

The picture below shows the material of the rock, and I will not introduce it.
Please add a picture description
Finally, add the rock to the vegetation, as shown below.
Please add a picture description
After that, you can brush the rock.
Please add a picture description
The creation of other plants is the same as above, and the final effect is as follows
Please add a picture description

5. Create game controllers including (game mode, player controller, pawn)

1. Game mode

GameMode defines our current game. It defines the game rules, scoring, which actors are allowed to exist in the game, and who can enter the game.
Please add a picture description
After creating the GameMode, you need to set **"Player Control Class" and "Default Pawn Class"** in the GameMode, and set the GameMode we created in the project settings, as shown in Figure 2
Please add a picture description
Please add a picture description

2. Player Controller

As the interface between the character and the player in the game, the PlayerController essentially represents the will of the player. Usually, we define all the input of the character in the PlayerController, especially for some complex situations, such as multi-player games or game running In games that dynamically change characters, the PlayerController issues commands to the characters in these games.

In addition, in some cases, it is necessary to define the input in PlayerController. For example, a character like Super Mario may die and respawn. After rebirth, a new character will be obtained, causing the data stored on the character to be reset. But PlayerController persists throughout the game, such as gold coins in Mario, because they exist in PlayerController, they will not be reset.
Please add a picture description
The player's control is not placed in the Controller, but in the Pawn, but it does not affect the operation of the game, because this is a single-player single-player game

3、Pawn

Pawn is a subclass of Actor, which can act as an avatar or character in the game (such as a character in the game).
Please add a picture description
We will give the character movement and steering functions in "MyCharacter". These input functions are almost directly bound to the entire game. (It will not change with the change of the game state, for example, W changes from walking forward to releasing skills), so we directly configure it in the input settings as shown in the figure below and then assign functions to these input events, as shown in the figure
Please add a picture description
below
Please add a picture description

6. Add an animation blueprint to the character to control the character's movement

Use the animation blueprint that comes with UE to realize

1. Import the corresponding mesh body, skeleton, and animation sequence of the character

The character material settings are as follows:
Please add a picture description
Please add a picture description

2. Create an animation blueprint, and go back to the character to change the "animation mode" to use the animation blueprint, and change the "animation class" to the animation blueprint just created , as shown in Figure 2

Please add a picture description
Please add a picture description

3. Use the state machine to control the animation, which are the transitions between Idel, Walk, and Run

1. Create a state machine node and connect

Please add a picture description

2. Set conversion conditions and corresponding actions in the state machine

General graph
Please add a picture description
Idel node
Please add a picture description
Idel To Walk condition
Please add a picture description
Walk To Idel condition
Please add a picture description

The Walk/Run node is described separately in 4

4、Walk/Run

Here we set Walk/Run to the same state, and change the character animation through the speed value on the character: we
need to get the character speed first, as follows, define Speed ​​in the event graph of the blueprint, and assign it to
Please add a picture description
create a mixed animation, and Expose the control variable Speed ​​of the mixed animation, as shown in Figure 2 **"horizontal coordinates" setting**
Please add a picture description
Please add a picture description
set the Walk/Run node
Please add a picture description

7. Create the NPC in the scene that is AI (AIController+NavMeshBoundsVolume component)

Create AIController; set AIController to NPC in the scene; add pathfinding detection NacMeshBoundsVolume in the scene; write AIController blueprint, the logic of NPC getting the target
Please add a picture descriptionPlease add a picture description
Please add a picture description
Please add a picture description
AIController will give Tips in 8
: P can switch the visibility of NavMeshBoundsVolume component

8. Add the function of "laying eggs" to the soles of the feet, and add pathfinding to the position of the eggs for AI

Create the "egg" blueprint (inherited from Actor); create the "egg laying" logic in PlayerController; create the "egg hunting" logic in AIController (including the implementation of the FindBall function + the logic after the NPC finds the egg); in the "egg" blueprint Realize overlapping and destroying its own logic
in the above implementation respectively corresponding to the following 5 diagrams
Please add a picture descriptionPlease add a picture description
Please add a picture description
Please add a picture description
Please add a picture description

9. Rich interactions in scenes (buttons + doors)

1. Use overlap detection to realize the switch function of the button

When the button overlaps with other objects, perform a downward movement on the button to simulate pressing and trigger the collision start event of the "collision detection component" (see below for details); when the overlap ends, the setting of the timeline node is as
Please add a picture description
follows
Please add a picture description

2. Create a collision detection component to monitor button presses and pop-ups

The collision detection component inherits from ActorComponent and can be attached to any Actor, and the component undertakes the function of event distribution
Please add a picture description

3. Open and close the door according to the trigger event of the collision detection component

Define the "OpenDoor" and "CloseDoor" events, and detect the collision detection component on the button object. If there is a collision, execute "OpenDoor"; otherwise, execute "CloseDoor". Note that the Trigger in the lower left corner needs to be opened (eyes open), in
order
Please add a picture description
The setting of the timeline node of its object can be specified in the scene
Please add a picture description
as follows Finally, we need to specify the trigger of the door in the scene (drag the corresponding button into it)
Please add a picture description

10. Add dust effect (special effect) to the movement of characters in the scene

Create a Dust effect; mount it on the frame corresponding to the animation
Please add a picture description
Please add a picture description
Please add a picture description
Please add a picture description

11. Add sound to the character walking

Same as the hook effect, except that the created object becomes a sound effect
Please add a picture description
Please add a picture description
Please add a picture description

12. Add shake to the camera when the door opens

UE comes with the base class of camera shake, which can be used directly. After creation, you only need to play the camera shake after the door switch state changes (as shown in the last picture of this chapter)
Please add a picture description
Please add a picture description
Please add a picture description

13. Game packaging

Please add a picture description
If there is a warning sign on the left side of the picture above, such as Android, just update/download the corresponding SDK (find it in Visual Studio)

Guess you like

Origin blog.csdn.net/weixin_40301728/article/details/129677565