The last video shows the ai enemy switching from idle state to run state, and then to attack state.
demo
In fact, the development of the ai enemy system takes far more time and energy than what is described on my blog.
In fact, the development of the ai enemy system takes far more time and energy than what is described on my blog. During the development process, a lot of problems were encountered, and a lot of problems and bugs were solved.
But luckily everything is ok now.
Tomorrow I will start boss research and development.
But the polygon meshes for the ai enemies still need to be subdivided, because I am going to add skeleton to them next.
Above is the subdivided polygon. My next step is to create the skeleton.
But I want to reduce the time of do animation, I will apply the same set of skeletons on these three ai enemies. in this way I can use a common set of animations for the ai enemies.
Because the ai enemy is not humanoid, but columnar (Anqing Sun hopes to use this to satirize Covid). So I can use custom bones. Because AI enemies are relatively simple, very simple bones can describe their animations.
The bones selected in the above picture are simulated with unity.
I will record a final version of the ai enemy system tomorrow after debugging the ai enemy code.
Simply put, what I need is to create a custom class. Then edit the four states, each of which are using my custom class.
This aiAgent.cs script can be regarded as the core of the ai system.
state example
Take this attack state as an example, it is not a script inherited from MonoBehaviour but inherited from aiState.
Below I will introduce the settings of the unity editor interface.
First select the area where the ai can act and the size of the ai under the Navigation tab. After completing the settings, the active area of ai can be baked.
The light blue area is the range of activity of the baked ai.
As I said before, I will only briefly discuss the code part of the ai system in the blog.
When I was developing the code part of the ai system, Anqing Sun had already sent me the design of the ai enemy.
After my friendly communication with Anqing Sun, the types of AI enemies have been reduced from 7 in the picture to 3 in the red box.
We just finished all the works on protagonist. In fact, I spent a day yesterday to complete the code part of the character controller: attack judgment, life value, environment interaction, etc.
Fortunately, this part has come to an end. And I have handed over this part to level editor Zixuan Wang. She will pick functions I developed to build game levels under the supervision of game designer Anqing Sun.
Now my job comes to the research and development of AI enemies.
This is an uncharted territory for me. After a quick search I found that this would involve a lot of coding work.
Thanks YouTube University. Someone has already prepared a tutorial for me.
It took me about three days to figure out the three hour tutorial. Thanks to the authors of this series:
He is really a very cool guy and a great teacher.
I’ll talk a little bit about the ai enemy system in the next bolg.
I first tried to use a death animation to show that the player was injured and fell to the ground. But I found the effect to be particularly bad, because the player may die during the fall or on the slope. If you just play the animation, it is very likely that the character cannot stick to the ground.
Fortunately, mature commercial games on the market have already given the answer 25 years ago: ragdoll.
Rocket Jockey (1996)Red Dead Redemption 2 (2018)
It is not difficult to see from the few references I gave that the ragdoll system has been used in 3D games for a long time. As the most widely used commercial game engine, the Unity engine naturally supports the ragdoll system.
now let’s set up a ragdoll.
Unity integrates a tool to create a ragdoll system. Developers only need to specify the corresponding joints to complete the first step.
automatic generatedmanual modification
Observing the above two pictures, it can be seen that the collision automatically generated by the unity engine is not perfect. So I still need to manually modify the collision of each joint to make the effect of ragdoll the best.
Looks good doesn’t it?
The ragdoll technique is also widely used in the animation of crowd simulation. This is a technique that can save animators a lot of work.
I will not discuss the operation of calling the KCC parameter synchronization state machine too much here, because it will involve a lot of code.
I recorded a demo here. In fact, this includes far more than character animation. In the process, I also need to synchronize the running animation with the character’s moving distance, and solve many problems such as camera movement.
But the character still has armed state, so another set of armed clips needs to be prepared for the same running and jumping clips.
In addition to the moving animation, the character also has slashing animation and death animation.
I have figured out the slashing animation as two new states.
Here I use the animation layer. I can control the weight of the layer. I’ll record another demo video to illustrate.
When the weight is 1, the character will appear to be holding a sword, and when the weight is 0, the character will appear to be empty-handed.
The last is the jumping state. Thanks to the developers of KCC, the developers can obtain the status of the character in the air in real time, which is expressed as a bool.
I exposed the airborne detection of the character in the KCC to the state machine of the character. When the character is detected to be in the air, jump animation will be played. The jump animation plays not only when the player presses the space bar, but also when the character falls from a height.
At the end of this blog plge I recorded a complete character controller demo.
Below is my list of animation clips:
[ UNARMED ] walk forward, walk backward, right strafe, left strafe (mirrored right strafe), jump, idle.
[ ARMED ] walk forward, walk backward, right strafe, left strafe (mirrored right strafe), jump, idle.
After reading the kcc documentation for a while, I probably found a few APIs that I need to call:
But i think i am going to blast turning rate. Cuz i found referening turning rate may cause some bugs that I cant fix.
Before starting build the character controller. I need to build the character animation state machine.
A state machine is a network linking different animation clips, like running, jumping or fallling. Then the developer can set the current animation status of the character through parameters.
Here is a blend tree in the state machine.
Red arrows represent horizontal velocity, blue arrows represent vertical velocity. And each point represents an animation clip. Developers can input the vertical speed and horizontal speed to control the character’s current animation state.
The animation state of the character is shown as a red dot in this coordinate system. When the red point is between two points, the unity engine will calculate the difference between the two points. In this way, the length of the input velocity vector controls the running speed of the character.
I recorded a short demo.
I’ll be combining the animation state machine with the character controller tomorrow morning.
At first I tried to construct a At first I tried to construct a character controller from 0, but after a simple trial I found it almost impossible. Because as an action-adventure game, the character controller needs to detect and return data in real time with the surrounding environment of the character. For example, whether the player is in the air, the player’s speed, the player’s steering angular velocity, the player’s jumping state, etc. from 0, but after a simple trial I found it almost impossible. Because as an action-adventure game, the character controller needs to detect and return data in real time with the surrounding environment of the character. For example, whether the player is in the air, the player’s speed, the player’s steering angular velocity, the player’s jumping state, etc.
Fortunately, earlier this year, unity officially acquired the well-known Kinematic Character Controller plug-in: Kinematic Character Controller. So now the price of Kinematic Character Controller in asset store is free. But although we will use the existing Character Controller, I still need to spend time to understand the various APIs of the Kinematic Character Controller.
I found a KCC tutorial on YouTube, and let me play around with it.
Before everything starts, I would like to strongly recommend Animation Rigging in the unity package manager.
Because we know that even in Maya, it is very troublesome for developers to choose a certain joint, let alone in the game engine.
But Animation Rigging can help developers to easily select the character’s bones because it can visualize the bones.
This is really an extremely useful plugin XD
OK ! then comes to the cloak.
magica cloth is the most popular simulation plugin among game developers. Specifically reflected in its extremely high universality has only occupied very few resources.
This is a magica cloth tutorial I refer to, the content in the tutorial is very useful.
I have summarized and written the steps for setting up the magica cloth below:
The first step is to create a magic bone cloth. It should be noted that magic bone cloth needs to bind the character’s clothes. Unbound clothes will consume a lot of computing resources.
that’s it! It’s so simple. Let’s take a look at the simulation.
Everything looks fine. But the cloak will go into the body when the character moves, what is more the character needs to jump, attack and other actions when running the game.
The solution is to add collisions to the character’s spine and shoulders.
Now that we’re done adding collisions let’s simulate it again.
ok, we just figured out the cloak.
In the next few days I will be working on several character controller solutions.
The rendering in the game engine is different from the developer-packaged renderers such as Arnold or octane. The rendering pipeline in the game engine allows developers to program the rendering pipeline to achieve a lot of cool effects.
Fortunately, I spent more than a month learning graphics programming (hlsl) during the last summer holiday (followed Herman’s advice). This more than a month of study has helped me greatly enhance my control over the game engine rendering, and allow me to control every frames in the game as I like.
The above picture explains the Rasterization Rendering。
In the current case, the graphics programming I use mainly focuses on the first step of Culling. Even more interesting: I can even animate the rendering pipeline.
After fully consideration, I still don’t want to introduce too much rendering knowledge in the blog. Because it will be almost impossible to fully explain Rasterization Rendering, because it will require a lot of words.
anyway, Zixuan Wang has uploaded the character’s textures.
I used Amplify Shader Editor here for graphics programming instead of code. Because ase can convert code into graph nodes, and this will greatly speed up my development speed.
I will talk about FX animations used in the future blogs.