[开发者心得] 手动k帧·武器变化动画

[复制链接]
1015 |2
脑的研发记录 发表于 2023-12-29 19:56:45 | 显示全部楼层 |阅读模式
本帖最后由 脑的研发记录 于 2023-12-29 19:56 编辑

手动k帧·武器变化动画
所用编辑器版本0.27.0.3
可行性方案来源,
找大佬教一教,最好能有个案例 口袋方舟论坛|面向全年龄的UGC互动内容平台与交流社区 (ark.online)


效果如视频



但是
每一帧的模型都是一个预制体
image.png

image.png
工程样例在最后。


代码成分:

对角色换装扮,每100ms换一次
最后有个obj变量,是测试插槽装入预制体不通过预制角色模型来切换。但是插槽上的预制体不能修改碰撞。





@UIBind('')
export default class DefaultUI extends UIScript {
    private character: Character;
    private anim1 = null;

    /** 仅在游戏时间对非模板实例调用一次 */
    protected onStart() {
        //设置能否每帧触发onUpdate
        this.canUpdate = false;

        //找到对应的跳跃按钮
        const jumpBtn = this.uiWidgetBase.findChildByPath('RootCanvas/Button_Jump') as Button
        const attackBtn = this.uiWidgetBase.findChildByPath('RootCanvas/Button_Attack') as Button


        //点击跳跃按钮,异步获取人物后执行跳跃
        jumpBtn.onPressed.add(() => {
            if (this.character) {
                this.character.jump();
            } else {
                Player.asyncGetLocalPlayer().then((player) => {
                    this.character = player.character;
                    //角色执行跳跃功能
                    this.character.jump();

                });
            }
            //跳跃时,同步数据
            this.character.syncDescription()
        })


        //点击攻击按钮,异步获取人物后执行攻击动作
        attackBtn.onPressed.add(async () => {
            Player.asyncGetLocalPlayer().then((player) => {
                this.character = player.character;
                //此时为自己端可见
                // this.character.setDescription(["7736CC584DE7B865DD0D5C94093C121A"])
                // setTimeout(() => {
                //  this.character.setDescription(["BBD879D54E57A4BF552BA58A9112C942"])
                // }, 100);

                // setTimeout(() => {
                //  this.character.setDescription(["EE2CC4A446203B1220DFD9ACA48E063D"])
                // }, 200);


                // setTimeout(() => {
                //  this.character.setDescription(["24DCDC7847DDE7F7ABE4B48B5212AA78"])
                // }, 300);


                // setTimeout(() => {
                //  this.character.setDescription(["AF87C86C4932CC9C14756CB8855827D3"])
                // }, 400);
            });

            this.character.setDescription(["7736CC584DE7B865DD0D5C94093C121A"])
            setTimeout(() => {
                this.character.setDescription(["BBD879D54E57A4BF552BA58A9112C942"])
            }, 100);

            setTimeout(() => {
                this.character.setDescription(["EE2CC4A446203B1220DFD9ACA48E063D"])
            }, 200);


            setTimeout(() => {
                this.character.setDescription(["24DCDC7847DDE7F7ABE4B48B5212AA78"])
            }, 300);


            setTimeout(() => {
                this.character.setDescription(["AF87C86C4932CC9C14756CB8855827D3"])
            }, 400);


            let obj = GameObject.asyncSpawn("ADA9DFAD46B9130660B099BED4F464A5");



            this.character.attachToSlot(await obj, HumanoidSlotType.RightHand);

            let box = GameObject.spawn("ADA9DFAD46B9130660B099BED4F464A5", {
                transform: new Transform(new Vector(300, 50, 250),
                    new Rotation(0, 0, 0), new Vector(1, 1, 1)),
                replicates: true
            }) as Model;


            (await obj).setCollision(PropertyStatus.On);

            box.setCollision(PropertyStatus.On);


            // setTimeout(() => {
            //  Player.asyncGetLocalPlayer().then((player) => {
            //      this.character = player.character;
            //      //此时为自己端可见
            //      this.character.setDescription(["BBD879D54E57A4BF552BA58A9112C942"])

            //  });
            // }, 100);

            // setTimeout(() => {
            //  Player.asyncGetLocalPlayer().then((player) => {
            //      this.character = player.character;
            //      //此时为自己端可见
            //      this.character.setDescription(["EE2CC4A446203B1220DFD9ACA48E063D"])

            //  });
            // }, 200);

            // setTimeout(() => {
            //  Player.asyncGetLocalPlayer().then((player) => {
            //      this.character = player.character;
            //      //此时为自己端可见
            //      this.character.setDescription(["24DCDC7847DDE7F7ABE4B48B5212AA78"])

            //  });
            // }, 300);

            // setTimeout(() => {
            //  Player.asyncGetLocalPlayer().then((player) => {
            //      this.character = player.character;
            //      //此时为自己端可见
            //      this.character.setDescription(["AF87C86C4932CC9C14756CB8855827D3"])

            //  });
            // }, 400);
        })

    }



}




优化方向:
源于之前整的文案“数据结构课作业笔记”#012-数组-二维数组-地雷冲击波-并发 口袋方舟论坛|面向全年龄的UGC互动内容平台与交流社区 (ark.online)
,当时想把像素编辑器改造成体素编辑器,但是又讲不清到的干啥用,和口袋方舟拖动方块又有什么不同。
这次手动k帧能粗略效果做出来,就是想着用API整个不用手动K帧,能像画动画一样,把每一百毫秒的效果变化直接画出来,然后一键导出。
然后导出数据,再做一个接口,再导入数据。就像动效编辑器那样,不过动效的元素就都是带碰撞的方块圆柱啥的啥的,不是动效的贴图了。理想的好处是能够手搓动效。

大概实际是类似于附带了生成顺序的预制体。预制体不是一次性生成的,而是每隔100毫秒就生成几个方块这样的。然后这样的预制体加进到什么地雷,什么炮弹击中目标的情形。
带碰撞效果的身临其境的大动画可还行emm。
踩着地雷自动播放方块掉落啥啥的。



手动k帧的工程
slotTest.zip (106 KB, 下载次数: 55)
image.png
回复

使用道具 举报

复读机读复读机 发表于 2024-1-2 18:24:12 | 显示全部楼层
20240102182216_rec_.gif

这是在发射吗,真的帅
回复

使用道具 举报

脑的研发记录楼主 发表于 2024-1-4 20:32:58 | 显示全部楼层
复读机读复读机 发表于 2024-1-2 18:24
这是在发射吗,真的帅

利刃出鞘 !
我假期把预制体动画绑到炮台上整一个看看
回复

使用道具 举报

热门版块
快速回复 返回顶部 返回列表