迷雾系统-人物驱散迷雾

使用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;
相关推荐
搬砖工程师Cola23 分钟前
<C#>在 C# .NET 6 中,使用IWebHostEnvironment获取Web应用程序的运行信息。
开发语言·c#·.net
Dazer0076 小时前
C# 运行web项目
c#
xiaowu0809 小时前
C#设计模式-状态模式
设计模式·c#·状态模式
风雅颂FYS12 小时前
C# 经纬度坐标的精度及WGS84(谷歌)、GCJ02(高德)、BD09(百度)坐标相互转换(含高精度转换)
百度·c#
姜行运13 小时前
每日算法(双指针算法)(Day 1)
c++·算法·c#
vil du16 小时前
c# 反射及优缺点
c#
三天不学习17 小时前
C# + Python混合开发实战:优势互补构建高效应用
开发语言·python·c#
谢道韫66617 小时前
37-串联所有单词的子串
开发语言·算法·c#
CodeCraft Studio19 小时前
PDF处理控件Aspose.PDF指南:使用 C# 从 PDF 文档中删除页面
前端·pdf·c#
全栈小519 小时前
【C#】Html转Pdf,Spire和iTextSharp结合,.net framework 4.8
pdf·c#·html