[UE5 Actual Combat] A vegetable cat like me can actually play games~ Hand-made hand-made bowling games—UE5 study notes (15)

foreword

I started to follow the tutorial today and make my first UE5 game.

The original tutorial of the game is quoted from a tutorial book, which will be introduced to you after this tutorial is completed.

The game is very simple, but I am still confused after reading the original tutorial, because the way of explaining is more procedural and difficult to eat, so I reorganized this tutorial in my own way here, hoping to provide it to students in need help.

As a game player, when learning the game production process, technology is one aspect, and more importantly, a good habit of thinking is required . After clarifying the design ideas, you can ensure that the ideas of the things you make are clear, instead of following the tutorials to avoid confusion after throwing away the tutorials.

There are a lot of actual combat pictures in this article, mainly aimed at UE5 blueprint beginners, it is recommended to collect ❤️, open Unreal Engine to do it step by step, how to do each step, why do it, there are detailed instructions, if there is something unclear , you can also private message me at any time!

Let's get started!

In this tutorial, you will learn how to design the game, create the game scene and interface , use the blueprint to implement the game rules , and finally complete the game by using the mouse to control the force and angle of throwing the bowling ball and hitting the cylinder.

_(:z」∠)_

When you finish this tutorial, I believe you can already master the use of basic blueprints , and you will be exposed to a simple game design process , laying a solid foundation for the next study!

^0^

Note: Newbies to this tutorial will take about 10-15 hours.


Table of contents

1. Make a plan

2. Game background

3. UI Layout

【Knowledge points】Usage of anchor point Anchor

[Knowledge Points] Use of Progress Bar

[Knowledge Points] The use of control containers

4. Blueprint structure planning

5. Initialization

1. Display UI

2. Create the sphere

3. Create a box

6. Mouse Control

1. Hold down the left mouse button to increase the power of the ball

2. Release the left mouse button to launch

3. The direction of the mouse controls the launching direction of the sphere

7. End Judgment

1. Judging the end of a single round

2. Judging the end of the game

3. Game end processing

8. Connect all functions in series

1. First run

2. Run every frame

3. Final adjustment

[End of flowering!


1. Make a plan

Before making a game, draw a mind map and the most basic interface design diagram, which can help us clarify our thinking and make plans for the next production content. Here you can directly see what the vegetable chicken blogger draws by himself, or try to make one yourself.

brain map

interface design

Although a bit crude, the meaning is basically clear.

According to the brain map above, the steps to split the game production are:

  • Complete the game background and UI layout

  • Use the mouse to throw the ball, and control the direction and strength

  • The game ends when the columns are all down



2. Game background

First build the game scene.

Create a new level (File>new level), here select the basic default level type with only the ground.

Next complete:

1. Expand the ground (change the scale value of the ground object)

2. Add a sphere and four boxes (drag the prefab into the scene and adjust the size and position)

(It is mentioned later that there is a pit that is not too big or small, so I will warn you here first)

3. Add material to all objects (drag the material onto the prefab)

After completion, you can get the following effect. All the materials in the picture come from the starter package. Please remember to check the starter package when creating a project. Of course, it doesn't matter if it is not checked, the material will not affect any logic, and you can also choose a color material to fill it in:

[relevant knowledge point reference]

How to create objects https://blog.csdn.net/weixin_35106335/article/details/127441304



3. UI Layout

Create a new control blueprint. The new method is described in detail in the previous notes. If necessary, please jump to the reference knowledge point below.

According to the design drawing, three pieces of content are required, so the following arrangement is made:

Among them, some controls that were not used in the previous article are used, here is a list:

Through the control container, multiple controls are combined into a whole, which is convenient for subsequent adjustment and management.

Next, bind the text in the middle with the text in the upper right corner. The binding method is described in detail in front of it. Students who need it can check the jump link in the reference knowledge point below.

【Knowledge points】Usage of anchor point Anchor

Students who have used unity must be familiar with this interface. That's right, UE also has this set of Anchor systems, and the shortcut keys are almost the same. I don't know what the order of existence is. Haha.

Here is a brief introduction to the role of anchor points. There is a huge chrysanthemum on the interface editor, and the small grid inside represents the relative relationship between the control and the chrysanthemum when the chrysanthemum appears in different positions.

This is used for screen adaptation. For example, if you select the square in the upper left corner of the screen, it means that the small chrysanthemum is in the upper left corner, and the relative position of this control and the small chrysanthemum remains unchanged. That is to say, no matter how long or high the screen is, this control will definitely appear in the upper left corner.

[Knowledge Points] Use of Progress Bar

1. Size setting: The size of the progress bar can be set freely under normal circumstances. If it is in the control container, it will become another set of setting methods. Currently, it supports automatic (varies according to the control container), filling (filling the control The container is left with controls), and the length can be set freely

2. Ratio display mode: Bar Fill Type is also a very common setting content, which controls the filling process of the progress bar from empty to full

Because they are the simplest English words, you can understand them at a glance and learn them, so I won’t sort them out here.

[Knowledge Points] The use of control containers

The control container is a relatively novel concept. The usage seen so far is that multiple controls can be placed in it to form a control group. In UI design software or other development software, controls will have the concept of grouping to help users organize a large number of controls on the interface. (Whether UE has this function, or whether its function is replaced by the control container, I am currently a novice and I am not sure. I will update the content after confirmation)

[relevant knowledge point reference]

How to build an interface https://blog.csdn.net/weixin_35106335/article/details/127637553



4. Blueprint structure planning

Now enter the critical blueprint stage.

According to the previous functional logic, all the blueprints are divided into functions. Simply put, it is to combine a complete simple logic into one function. This is the structuring mentioned earlier. This method can make the whole blueprint structure clear.

According to the brain map, the game is divided into four parts according to the content: initialization, mouse control, end processing, and connection of all functions.

According to these four blocks and then split down the function, the following functions are obtained. If possible, break down the functions as much as possible. The finer the break down at the beginning, the easier it is to write each individual function.

It doesn't matter if you can't sort it out, you can sort out this table again during the writing process.

category

Function name

Implementation content

initialization

Set UI

display UI

Create Ball

Initialize the sphere

Create Boxes

Initialize the box

mouse control

Mouse Button Down

Press and hold the left mouse button to adjust the intensity

Mouse Button Up

Release the left mouse button to launch

Mouse Move UpDown

Mouse movement controls the angle of the sphere (up and down)

Mouse Move LeftRight

Mouse movement controls the angle of the sphere (left and right)

end processing

Is Turn Over

Determine whether the sphere stops, used to determine whether the current round is over

Is Win

Judging whether all the boxes are down, used to judge whether the game is over

Game Over

Handling at the end of the game

[relevant knowledge point reference]

What is the structure of blueprint https://blog.csdn.net/weixin_35106335/article/details/127382868



5. Initialization

According to the function diagram above, we can start the function design. Most of the blueprints are completed in the level blueprint, so you can open the level blueprint first, and drag the tab to the side of the main level at the top for easy switching.

1. Display UI

First add the necessary function SetUI and variable UI to the blueprint. The type of the variable UI is changed to the previously built UI file. The name here is the relatively simple two letters of UI.

Then double-click SetUI to open this function, and add blueprint logic in it.

The nodes used are:

After connecting get:

Because I want to see the results of each modification, I connect the completed function to BeginGame, and after running, I get:

【Finish!

2. Create the sphere

Consider first the logical content needed to create a sphere:

1. Create a sphere

2. Initialize the position of the sphere

3. Initialize the sphere settings

4. Add one to the sphere count

Add the function Create Ball and the variable Ball and the variable Count related to creating a sphere:

Among them, the grid control variable of the sphere needs to modify the type, and the method is as follows.

Then double-click the function Create Ball to start adding nodes, and divide the nodes into three groups according to the logical content:

Connect all the above blueprints, adjust the parameters, and match the notes:

Add it after beginplay, run it, perfect, another ball appears in the scene.

Note: At this time, it is found that the sphere has no material. This is because when adding material to the sphere, it was directly dragged onto the created object. To solve this problem, you need to open the object, add a material to the mesh, and the material will only be included when you create a new one.

【Finish!

3. Create a box

First analyze the needs:

1. Need to build 5 boxes

2. Each box is random in a certain range

3. Set the physics engine for the box

Add the function Create Boxes and the variable Boxes:

Among them, the establishment method of the variable Boxes is the same as the above Ball, but after compiling, two contents need to be modified in the detail Detial, one is to modify into groups, and the other is to add the number of groups, currently 5 are added.

Then double-click Create Boxes to start adding blueprint nodes, and divide the nodes into 3 groups according to requirements:

Connect all the above blueprints, adjust the parameters, and match the notes:

Connect to BeginPlay and run it, the box will drop from the sky (laugh cry):

But something is not right here, so I realized that when I first started building objects, I was lazy and used the default box creation and stretching in UE, because the default box does not need to be converted into a static mesh Objects with their own collisions. (This is the pit mentioned above)

But I didn't realize one thing at the time: the preset body and the instantiated object are two things, so when I modify the instantiated object, the preset body does not change.

So being lazy, I have to pay the price and rebuild all the objects...

The correct way to create it is this:

1. Use a graphic brush to make graphics on the map and adjust the size (it is best to adjust the size after drawing, it will be difficult to adjust after turning, don't ask me how I know)

2. Convert it to a static grid graphic, save it as a prefab, and give it a good name.

3. Double-click the graphic, add a collision body after entering, add a material, check the shadow and independent

4. After saving, delete the objects in the original scene, and then you can create objects through the blueprint. The object created this time can be changed as you want.

After some operations, I replaced the originally created sphere and box with objects created by myself.

And adjusted the size and position appropriately, so the following effect is completed:

【Finish!



6. Mouse Control

1. Hold down the left mouse button to increase the power of the ball

First analyze the needs:

1. Determine whether to hold down the left button

2. When the left button is pressed, the percentage increases with time

3. When the percentage reaches 1, keep 1 unchanged

Then create the required function Mouse Button Down and function Delta

Since the progress bar is used, in order to avoid the name confusion of the progress bar, go back to the blueprint of the UI and change the three progress bars to easy-to-recognize names.

Add relevant nodes for this requirement, and divide them into four groups according to the content:

Connect all the above blueprints, adjust the parameters, and match the notes:

Connect the function to BeginPlay as usual, run it, and find that there is no effect, is it broken?

Of course not, first look at the blueprint, there is a key detla value that has not been assigned. Don't worry, this value will change over time, since there are other values ​​that change over time, we will solve it together when dealing with time. Here we can do temporary processing first to verify availability.

Secondly, the function for judging the keyboard click should be connected to the Tick of each frame. We adjust it and run it again. After clicking the left mouse button, we find that the progress bar in the lower left corner has changed:

【Finish!

2. Release the left mouse button to launch

First analyze the needs:

1. When the left mouse button is released, push the sphere

2. The pushing force depends on the strength and angle

Create the related function MouseButtonUp and the variable IsMove (boolean type). The default value of this variable is true, which is used to determine whether the ball is moving or completely stopped. When the sphere is moving, no force will be applied to the sphere. If you find that the sphere does not move, it may be that this value is not set correctly.

Add relevant nodes for this requirement, and divide the nodes into 3 groups according to the requirements:

Connect all the above blueprints, adjust the parameters, and match the notes:

Here is an explanation of what the minus 0.5 at the bottom does. The value processed here is the direction of the sphere from left to right, and the middle is 0, which is adjusted to be the force in the left and right directions by subtracting 0.5. Since the height value must not be negative above the ground, it does not need to be corrected.

Add the function to Tick and run it, and find that the ball seems to be kicked, and the function is achieved!

【Finish!

3. The direction of the mouse controls the launching direction of the sphere

The previous function used the two progress bar values ​​of DirectBar, but neither of these two progress bars has been assigned, so I will add it next.

First analyze the needs:

Mouse movement controls the direction of the sphere

This time the content is relatively simple, the main purpose is to assign values, add the required function Mouse Move UpDown\Mouse Move LeftRight.

Add related nodes for requirements, divided into 2 groups:

Connect all the above blueprints, adjust the parameters, and match the comments, and the two functions are completed:

There is a correction of -0.05 in the multiplication formula given above, which is used to correct the negative relationship and to control the percentage value of the mouse value more slowly. Interested students can change the value to 1 and see the effect in the game.

After connecting the two blueprints to Tick, you can test it in the game. If you find that XY is reversed during the test, or the value change is opposite to the mouse movement, you can check and fix it yourself. If there are any problems that cannot be solved, please PM me!

After running, you can control the direction of the ball to eject it!

Fly out slightly! Don't tell me, it's quite interesting!

【Finish!



7. End Judgment

The basic functions have been completed, and it's time for the rules around the game.

1. Judging the end of a single round

Analysis needs:

1. Determine whether the sphere stops

2. Destroy the sphere if stopped

3. Reset the values

First establish the required function IsTurnOver according to the requirements.

The following nodes need to be added, logically divided into 3 groups:

Connect all the above blueprints, adjust the parameters, and match the notes:

This function cannot be tested at present, because the required condition is that the sphere must stop in the moving state and the variable IsMove is enabled.

【Finish! Not tested]

2. Judging the end of the game

Analysis needs:

In the case of all the boxes falling down, the game wins

Create the required function Is Win and a local variable flag according to the requirements. Note that the local variables used here need to be established in local variables.

Briefly explain global variables and local variables. Global is a variable that can be seen in all blueprints, and local is a variable that can only be seen and used in one blueprint.

Organize the following nodes:

The last special node needs to add an output boolean value through details.

Connect all the above blueprints, adjust the parameters, and match the notes:

This function waits for subsequent tests.

【Finish! Not tested]

3. Game end processing

Analysis needs:

When the game is over, display "Game Over" and mark it as over

First add the function GameOVer, and the variable IsOver, which is used to identify whether the current game is over.

The nodes that need to be used are as follows:

Connect all the above blueprints and adjust the parameters. Since the content is relatively simple, no comments are added:

This function waits for subsequent tests.

【Finish! Not tested]



8. Connect all functions in series

In the previous function test, we also tried to connect the written function to BeginPlay and Tick to run. At present, all functions have been completed, and we will formally connect them.

1. First run

The first is BeginPlay. When we first start running the game, the functions and logic we will use are:

1. Initialize the sphere Create Ball

2. Initialize the box Create Boxes

3. Initialize UI Set UI

4. After the screen display starts for a while, the text disappears

Since the nodes used are simple, here is the blueprint directly:

A common node of delay is used here, and the usage is relatively simple, that is, to run the next node after a delay of xx time.

After compiling, enter the game and run it, there is no problem.

【Finish!

2. Run every frame

Next is Tick, Tick will make a judgment when each frame runs, and these judgments include:

1. Left mouse button press MouseButtonDown

2. Lift the left mouse button to MouseButtonUp

3. Mouse movement MouseMoveUpDown/MouseMoveLeftRight

4. Whether the sphere stops Is Turn Over

Since the nodes are simple, here is also directly on the blueprint:

There are two points to note:

The first one is to reduce invalid calculations, the node that assigns value to Delta is placed after the condition node.

The second is to use sequences to connect all nodes in parallel without affecting each other when the function has no causality.

This blueprint handles the Delta that has been seen but not used before. This value has been mentioned before, and it will be explained here again. This value is used here and will not have any effect on the current content. Its purpose is to correct the difference in frame rate between different devices through a unified time.

To give an inappropriate example, if two people are running, their steps will not be exactly the same, so the time to reach the end must be different. But if you don't look at the watch, every time this person takes a step, someone will measure his step length and convert his duration. The result is that no matter how many people there are, no matter how long or short the legs are, as long as they run the same distance, the time must be the same.

3. Final adjustment

At present, all the large blocks of logic have been completed, but after running, it is found that it still cannot work normally. This is because the critical conditions for concatenation have not been clearly connected.

So let's consider the key position of Boolean value switch change and judgment globally:

1. When you first enter the game, the ball is not launched and the movement stops, allowing the launch function to run

2. When the mouse is released, the ball has been launched, but the ball has not moved yet. At this time, wait for the ball to move, and then determine whether it is still. The game is not over

3. When the sphere has been launched and the movement stops, judge the condition of the box. If it is not all down, reset the sphere. If it is all down, the game is over


To sum up, there are three boolean switches for decision:

1. Whether the ball is moving IsMove (existing), true means moving, false means stop

2. Whether the game is over IsOver (existing), true is the end, false is the continuation

3. Whether the sphere emits IsShot (not available), true means it is emitted, false means it is not emitted


There are two ways to add boolean switches:

The first is to add a global boolean, which, like the two above, is used to modify this boolean in multiple functions.

The second is to add local variables that can be modified within a function. The advantage of this method is that the local variable is only controlled by one function, which is cleaner globally.

Here, whether the sphere is launched or not only needs to be controlled by MouseButtonUp, that is, it only needs to determine whether to apply force to the sphere when the button is lifted. After confirming that the sphere is launched, wait for the sphere to move, and then make a static judgment.

So add a local variable IsShot in MouseButtonUp, and use the result of this value as the outgoing value of MouseButtonUp to activate the next static judgment. Adjust the blueprint as follows:

Open MouseButtonUp and add a local variable.

If the pressure is not applied, the value will not be changed, if the pressure is applied, the value will be changed to true, and finally the value will be returned.

Open the blueprint where the Tick event is located, and make the following modifications:

When running until the button is lifted, if it works, change the boolean judgment value of the movement to true after a delay of 1 second.

Some students may have a question (such as me) when they do this, that is, from a logical point of view, this IsShot is actually used to control IsMove, but why does it need an additional local variable. After I tried this question, I found that the Delay node cannot be added in the function blueprint. As for why, please let me know the reason, please private message me to answer my questions!

Then there is the last step, which is to generate a ball again if the boxes are not all down. If all the boxes are down, the game is over. The IsTurnOver blueprint needs to be modified as follows:

After sorting out all the content, run it, actually check it, check the error reporting, check whether the logic is correct, and check whether the parameters are reasonable. There are generally no problems in the blueprint posted above, but there are some unreasonable places in the details, and some modifications and adjustments have been made in the follow-up, so I will not list them one by one here. Students can try to adjust it by themselves. If you encounter problems that cannot be solved, you can also private message me to discuss debugging together to find out the problem.

So far, this simple bowling game is basically completed. On this basis, it can be adjusted to be more interesting, such as changing the strength and direction below to the arrow on the sphere. For example, the box is not a box, but one by one. Moving cars, such as balls and various skills, can accelerate in the air and so on. All these funs are waiting for gamers to dig a little bit.

[End of flowering!

[For such a long tutorial, you can see it here, and I would like to express my heartfelt thanks to you!

【Your support is my driving force! If you have any questions, please reply or leave a private message!

Guess you like

Origin blog.csdn.net/weixin_35106335/article/details/127733846