+
110
-

回答

800_auto

你要找的是不是这个,身体左右摇晃,还可以设置摇摆幅度。

点击查看html代码

<!DOCTYPE html>
<html>
<head>
    <title>Live2D摇摆动画</title>
    <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/live2dcubismcore.js"></script>
    <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/live2d.js"></script>
    <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/pixi.6.5.2.js"></script>
    <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/pixi-live2d-display.index.min.js"></script>
    <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/pixi-live2d-display.extra.js"></script>
    <style>
        #live2d {
            pointer-events: none;
        }
    </style>
</head>
<body>
    <canvas id="live2d" width="300" height="500"></canvas>

    <script>
        (async function main() {
            const app = new PIXI.Application({
                view: document.getElementById('live2d'),
                autoStart: true,
                transparent: true,
                width: 600,
                height: 500
            });

            const model = await PIXI.live2d.Live2DModel.from('//repo.bfw.wiki/bfwrepo/images/live2dm3/Haru/Haru.model3.json');
            app.stage.addChild(model);

            // 调整位置和大小
            model.x = 0;
            model.y = 0;
            model.scale.set(0.3);

            // 摇摆动画
            let time = 0;
            app.ticker.add(() => {
                time += 0.03; // 降低摇摆速度

                // 禁用默认动作
                model.internalModel.motionManager.update = () => {};

                // 身体整体小幅度摇摆
                model.internalModel.coreModel.setParameterValueById(
                    'ParamBodyAngleX',  // 身体左右摇摆
                    Math.sin(time) * 30   // 减小摇摆幅度到3度
                );

                // 配合身体摇摆的头部轻微调整
                model.internalModel.coreModel.setParameterValueById(
                    'ParamAngleX',
                    Math.sin(time) * 20   // 头部配合身体轻微摇摆
                );
            });
        })();
    </script>
</body>
</html>

网友回复

我知道答案,我要回答