Unity中实现人物残影效果

今天火柴人联盟3公测了,看到一个残影的效果,很有意思,上网查询了一下实现方式,

实现思路:

将角色的网格复制出来,然后放置到新建的物体的MeshFilter组件上,每隔几十毫秒在玩家的位置生成一个,这样随着玩家移动,不断复制数个就会实现此效果。

实现代码:

cs 复制代码
public class CharacterTrail : MonoBehaviour
{
    public MeshFilter m_filter;
    public Material material;

    private void Start()
    {
        StartCoroutine(CreateMesh());
    }

    IEnumerator CreateMesh()
    {
        while (Application.isPlaying)
        {
            GameObject gameObject = new GameObject();
            gameObject.AddComponent<MeshFilter>().mesh = m_filter.mesh;
            gameObject.AddComponent<MeshRenderer>().sharedMaterial = material;
            gameObject.transform.position = transform.position;
            Destroy(gameObject, 0.7f);
            yield return new WaitForSeconds(0.1f);
        } 
    }
}

实现效果:

参考:

CHARACTER TRAIL TUTORIAL in Unity (youtube.com)

相关推荐
UWA3 小时前
隐藏视频变“常驻刺客”,VideoPlayer与“N/A”纹理该怎么查
人工智能·性能优化·音视频·memory·cpu·游戏开发
烬羽4 小时前
《React Router 受保护路由的 3 个坑,第 2 个 90% 的人都踩过》
react.js·性能优化·全栈
xcLeigh6 小时前
Unity基础:Light灯光组件入门——Directional Light、Point Light与Spotlight
unity·游戏引擎·教程
张龙6878 小时前
10 万条数据不卡顿:不定高虚拟列表从原理到生产实现
前端·javascript·性能优化
echoVic10 小时前
把 Orca 的 DeepSeek 缓存命中率打到 99%,我做了九轮优化
性能优化·ai编程·deepseek
郝学胜-神的一滴11 小时前
[简化版 GAMES 104] 现代游戏引擎 04:从0到1构建你的游戏世界
c++·游戏·unity·游戏引擎·软件工程·unreal engine
仙人球部落 揞殺11 小时前
Sql Server查询性能优化之走出索引的误区
数据库·性能优化
90后小陈老师16 小时前
从“打开就卡“到“秒开“:一次 PHP GD 动态海报生成的性能优化实战
开发语言·性能优化·php
是嘟嘟啊1 天前
【Unity DOTS】EntityCommandBuffer 与 JobHandle
unity·ecs·dots·unity dots·job·burst·burstjob
xcLeigh1 天前
Unity基础:Camera相机组件详解——透视投影与正交投影的区别
数码相机·unity·游戏引擎