当前位置:网站首页>King glory - unity learning journey
King glory - unity learning journey
2022-04-23 07:44:00 【0zien0】
I am completely unity The small white , Intend to write a simple King glory demo To learn unity Related knowledge .
The production process is certainly not the best solution , Just to use unity Functional modules of each major system .
This article mainly records the learning ( Make ) Some pits encountered in the process ( In fact, it's what Xiaobai doesn't understand ).
【 Animation 】
Animation tried to use unity Animation controller for , adopt UI Interface to do some simple animation switching logic , Then in the program, the condition variables are set to control the state switching .
I passed update To detect when the character moves to the destination , Change the character from run Change the state of idle state , I found that he would continue to run in place for a period of time before switching state , At first I thought update The logic is not good , All kinds of debugging …… Finally I found out that The animation controller is checked by default 【Has Exit Time】 Cause to have to wait run The animation state can be switched only after the animation is completely played , Later, remove this check box , It's normal .
【 Pathfinding 】
The self-contained routing component of the system is used NavMeshAgent. After I set the destination , Will switch the character's animation to run state , Then I need to know the moment he reaches his destination , Switch the character animation back to idle state . But I can't find the callback method to reach the destination in this pathfinding component …… In the end, we can only continue to update Check 【hasPath】 This value , When this value is from true turn false when , On behalf of his destination .
Here, too ! stay 【SetDestination】 after ,【hasPath】 You don't have to switch to... Right away true Of , It may not become... Until the next frame true.
【 Get the object that the player clicks on the screen 】
When the player clicks on the screen , We need to know what players actually click on the screen . I used 【Physics】 A ray is emitted into the game by the player clicking on the coordinates of the screen , Return to all intersections passing through this ray in the game .
But when players click on the screen, we often only need to know the unit that the player clicks on the top of the screen . and 【Physics.RaycastAll】 The intersection set returned is A disorderly ! A disorderly !!!
Finally, I traverse all objects that intersect with the ray , Find the product point in the front through .
// This ray may pass through multiple intersections ( For example, characters , Obstacles such as flowers and grass ), So when saving the target, use an array
RaycastHit[] hits = Physics.RaycastAll(ray, 200);
// Traverse all intersections
// Here's the description : because RaycastHit The intersection returned by the array is 【 disorder 】 Of !!! Here you only need to get the intersection closest to the screen ( Is the object displayed in the front in the click ), So after traversing, find the object in the front through the dot product
RaycastHit item = hits[0];
for (int i = 1; i < hits.Length; ++i)
{
float value = Vector3.Dot(item.transform.forward, hits[i].transform.position);
if (value > 0)
{
item = hits[i];
}
}
【 What is displayed on the character ( Like blood strips )】
programme 1: adopt Quaternion.LookRotation Method to obtain the rotation angle required for the front facing the camera
Transform baseTF = transform.parent;
Vector3 relativePos = baseTF.position - Camera.main.transform.position;
Quaternion rotation = Quaternion.LookRotation(relativePos);
baseTF.transform.rotation = rotation;
effect : It's true that the blood bar will be facing the camera , But the camera will follow the character , Cause the blood bar to move with the camera , The effect is extremely strange ( If the camera doesn't move , Maybe the effect is OK )
programme 2: Create a... On the character canvas, Then create a blood bar .
The production scheme is simple , The implementation principle is also simple , The effect is good . But there's a fatal flaw , One canvas I'll do it once drawcall, If there are hundreds of small soldiers , Execute hundreds of times drawcall, It's not worth consuming performance for a blood bar , I can't accept !
programme 3: Use WorldToScreenPoint
Just pass the player's coordinates through the method WorldToScreenPoint Convert to screen coordinates , You can easily set the position of the blood bar to the corresponding position on the screen .
This is also the solution I finally adopted .
版权声明
本文为[0zien0]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230623293309.html
边栏推荐
猜你喜欢
随机推荐
图论入门——建图
Mobile game performance optimization
MySQL storage engine
SAP PI/PO登录使用及基本功能简介
8.分页查询
自定义时间格式(YYYY-MM-DD HH:mm:ss 星期X)
FSM有限状态机
安装配置淘宝镜像npm(cnpm)
配置npm
Processing of common dependency module
VR、AR、MR的区别与应用,以及对AR技术的一些实现原理
Discussion on arrow function of ES6
5.SQL99标准:内连接和外连接
js之预解析
Implementation of MySQL persistence
SAP DEBUG调试FOR IN、REDUCE等复杂的语句
keytool: command not found
状态同步与帧同步
快速傅里叶变换FFT简明教程
Django使用mysql数据库报错解决