当前位置:网站首页>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
边栏推荐
猜你喜欢

SAP pi / PO rfc2soap publishes RFC interface as WS example

SAP PI/PO Soap2Proxy 消费外部ws示例

数据分析入门 | kaggle泰坦尼克任务(四)—>数据清洗及特征处理

SAP Excel 已完成文件级验证和修复。此工作簿的某些部分可能已被修复或丢弃。

Discussion on arrow function of ES6

SAP 导出Excel文件打开显示:“xxx“的文件格式和扩展名不匹配。文件可能已损坏或不安全。除非您信任其来源,否则请勿打开。是否仍要打开它?

SAP SALV14 后台输出SALV数据可直接保存文件,发送Email(带排序、超链接、筛选格式)

FSM有限状态机

keytool: command not found

canvas学习第一篇
随机推荐
[CodeForces - 208E] Blood Cousins(k代兄弟问题)
Authorization+Token+JWT
刨根问底---cocos2d源码的理解与分析
5. Sql99 standard: internal connection and external connection
2022.3.14 阿里笔试
js之预解析
SAP SALV14 后台输出SALV数据可直接保存文件,发送Email(带排序、超链接、筛选格式)
手游性能优化
Django使用mysql数据库报错解决
ABAP 从CDS VIEW 发布OData Service示例
反思 | Android 音视频缓存机制的系统性设计
数据分析入门 | kaggle泰坦尼克任务(三)—>探索数据分析
13. User and authority management
Thorough inquiry -- understanding and analysis of cocos2d source code
14. Transaction processing
js之什么是事件?事件三要素以及操作元素
5.SQL99标准:内连接和外连接
The difference and application of VR, AR and MR, as well as some implementation principles of AR technology
Reflection on the systematic design of Android audio and video caching mechanism
【自我激励系列】到底是什么真正阻碍了你?