迷雾系统-人物驱散迷雾

使用linerRender,将人物移动数据动态添加进去,同样是特殊层级让FogCamera渲染

EndCapVertices的数量越多,矩形就变为一个椭圆形的形状,更适合圆形视野探索

当拐点的两个点距离太近,LineRender会发生扭曲,解决方案是在拐点处额外新添几个点作为过渡

下面是我每次鼠标点击移动,就往LineRender里面多新填一行数据,预防拐点变形,我每次点击就新填几行无意义数据进去,超过50个,我就新生成LinerRender

csharp 复制代码
 if (Input.GetMouseButtonUp(0))
      {
         Move(Input.mousePosition);
      }
      
      if (_isCanMove)
      {
         transform.Translate(_dir.normalized*Time.deltaTime*_moveSpeed,Space.World);
         _addLineTimer += Time.deltaTime;
         if (_addLineTimer > 0.1f)
         {
            _addLineTimer = 0f;
            AddLineRender(transform.position);
         }
         
         if (Vector3.Distance(transform.position, _targetPos) < 0.5f)
         {
            transform.position = _targetPos;
            _isCanMove = false;
            AddLineRender(transform.position);
         }
      }

//上面是Update里面的操作
 private void AddLineRender(Vector3 pos)
   {
      _currentLineRenderer.positionCount = _linerIndex+1;
      _currentLineRenderer.SetPosition(_linerIndex,pos);
   }

//鼠标点击生成此方法
   public void Move(Vector2 targetPos)
   {
      if (_currentLineRenderer == null)
      {
         GameObject go = Instantiate(meshPrefab,meshPar.transform);
         go.transform.position = new Vector3(0f, 0f, 1f);
         _currentLineRenderer = go.GetComponent<LineRenderer>();
         _addLineTimer = 0.1f;
         _linerIndex = 0; 
         AddLineRender(transform.position);
      }

      if (_linerIndex > 50)
      {
         GameObject go = Instantiate(meshPrefab,meshPar.transform);
         go.transform.position = new Vector3(0f, 0f, 1f);
         _currentLineRenderer = go.GetComponent<LineRenderer>();
         _addLineTimer = 0.1f;
         _linerIndex = 0;
         AddLineRender(transform.position);
         _linerIndex += 1;
      }
      else
      {
         for (int i = 0; i < 3; i++)
         {
            AddLineRender(transform.position + new Vector3(0.01f*i, 0f, 0f));
            _linerIndex += 1;
         }
      }

//获取移动向量,物体往此方向移动
 Vector3 pos = cam.ScreenToWorldPoint(new Vector3(targetPos.x,targetPos.y,-10f));
      _targetPos = new Vector3(pos.x,pos.y,-9.5f);
      _dir = _targetPos - transform.position;
      _isCanMove = true;
相关推荐
游乐码8 小时前
c#变长关键字和参数默认值
学习·c#
全栈小59 小时前
【C#】合理使用DeepSeek相关AI应用为我们提供强有力的开发工具,在.net core 6.0框架下使用JsonNode动态解析json字符串,如何正确使用单问号和双问号做好空值处理
人工智能·c#·json·.netcore·deepseek
wearegogog1239 小时前
基于C#的TCP/IP通信客户端与服务器
服务器·tcp/ip·c#
A_nanda15 小时前
C#调用Quartz.NET的完整实现。
c#·.net·quartz
2501_9307077816 小时前
使用C#代码在 PowerPoint 演示文稿中插入表格
开发语言·c#·powerpoint
少控科技16 小时前
C#基础训练营 - 01 - 数据类型
开发语言·c#
1314lay_100716 小时前
Vue3 + Element Plus项目和C# .Net 7.0 Core后端API项目发布部署到服务器
服务器·前端·javascript·vue.js·elementui·c#·.net
郝亚军17 小时前
c#如何编译、通过icd文件生成static_model.c和static_model.h
开发语言·c#
Traced back17 小时前
保姆级C#进阶教程:从入门到企业级开发,小白也能秒懂!
开发语言·c#
柒儿吖18 小时前
CharLS 无损 JPEG-LS 库在 OpenHarmony 的 lycium 适配与 ctest 验证
c++·华为·c#·harmonyos