猫史档案馆


【结界】人物动作模拟器()

用户:迷失冷光迷失冷光查看:23 回复:15 评论:23 创建时间:2023-04-10T20:42:17


先说好只是人物的()

就是一个脑袋+身体+四肢的()

没有脖子()

做动物可以先走了()

上代码()

const Quat = new Box3Quaternion(0,0,0,1);
const Origin = new Box3Vector3(0,0,0);
class People{
    constructor({
        mesh: {
            headMesh,
            bodyMesh,
            left_upper_arm_mesh,
            right_upper_arm_mesh,
            left_lower_arm_mesh,
            right_lower_arm_mesh,
            left_upper_leg_mesh,
            right_upper_leg_mesh,
            left_lower_leg_mesh,
            right_lower_leg_mesh,
            left_hand_mesh,
            right_hand_mesh,
            left_foot_mesh,
            right_foot_mesh,
        },
        radius: {
            head_dist,
            neck_dist,
            shoulder_dist,
            upper_arm_dist,
            lower_arm_dist,
            upper_leg_dist,
            lower_leg_dist,
            hand_dist,
            foot_dist,
            hips_dist,
            ass_dist,
        },
        scale: {
            headScale,
            bodyScale,
            upper_arm_scale,
            lower_arm_scale,
            upper_leg_scale,
            lower_leg_scale,
            left_hand_scale,
            right_hand_scale,
            left_foot_scale,
            right_foot_scale,
        },
    }){
        this.body = create(bodyMesh,bodyScale);
        this.head = create(headMesh,headScale);
        this.left_upper_arm = create(left_upper_arm_mesh,upper_arm_scale);
        this.right_upper_arm = create(right_upper_arm_mesh,upper_arm_scale);
        this.left_lower_arm = create(left_lower_arm_mesh,lower_arm_scale);
        this.right_lower_arm = create(right_lower_arm_mesh,lower_arm_scale);
        this.left_upper_leg = create(left_upper_leg_mesh,upper_leg_scale);
        this.right_upper_leg = create(right_upper_leg_mesh,upper_leg_scale);
        this.left_lower_leg = create(left_lower_leg_mesh,lower_leg_scale);
        this.right_lower_leg = create(right_lower_leg_mesh,lower_leg_scale);
        this.left_hand = create(left_hand_mesh,left_hand_scale);
        this.right_hand = create(right_hand_mesh,right_hand_scale);
        this.left_foot = create(left_foot_mesh,left_foot_scale);
        this.right_foot = create(right_foot_mesh,right_foot_scale);
        this.parts = [this.body,this.head,this.left_upper_arm,this.right_upper_arm,this.left_lower_arm,this.right_lower_arm,this.left_upper_leg,
            this.right_upper_leg,this.left_lower_leg,this.right_lower_leg,this.left_hand,this.right_hand,this.left_foot,this.right_foot];
        Object.assign(this,{
            head_dist,
            neck_dist,
            shoulder_dist,
            upper_arm_dist,
            lower_arm_dist,
            upper_leg_dist,
            lower_leg_dist,
            hand_dist,
            foot_dist,
            hips_dist,
            ass_dist,
            angle: 0,
            up: 0,
            head_angle: 0,
            head_up: 0,
            left_upper_arm_angle: 0,
            left_upper_arm_up: 0,
            right_upper_arm_angle: 0,
            right_upper_arm_up: 0,
            left_lower_arm_angle: 0,
            left_lower_arm_up: 0,
            right_lower_arm_angle: 0,
            right_lower_arm_up: 0,
            left_hand_angle: 0,
            left_hand_up: 0,
            right_hand_angle: 0,
            right_hand_up: 0,
            left_upper_leg_angle: 0,
            left_upper_leg_up: 0,
            right_upper_leg_angle: 0,
            right_upper_leg_up: 0,
            left_lower_leg_angle: 0,
            left_lower_leg_up: 0,
            right_lower_leg_angle: 0,
            right_lower_leg_up: 0,
            left_foot_angle: 0,
            left_foot_up: 0,
            right_foot_angle: 0,
            right_foot_up: 0,
        });
    }
    setVelocity(velocity){
        for(const e of this.parts){
            e.velocity.copy(velocity);
        }
    }
    update(centerPos){
        rotate(this.body,this.angle,this.up);
        rotate(this.head,this.head_angle,this.head_up);
        rotate(this.left_upper_arm,this.left_upper_arm_angle,this.left_upper_arm_up);
        rotate(this.right_upper_arm,this.right_upper_arm_angle,this.right_upper_arm_up);
        rotate(this.left_lower_arm,this.left_lower_arm_angle,this.left_lower_arm_up);
        rotate(this.right_lower_arm,this.right_lower_arm_angle,this.right_lower_arm_up);
        rotate(this.left_hand,this.left_hand_angle,this.left_hand_up);
        rotate(this.right_hand,this.right_hand_angle,this.right_hand_up);
        rotate(this.left_upper_leg,this.left_upper_leg_angle,this.left_upper_leg_up);
        rotate(this.right_upper_leg,this.right_upper_leg_angle,this.right_upper_leg_up);
        rotate(this.left_lower_leg,this.left_lower_leg_angle,this.left_lower_leg_up);
        rotate(this.right_lower_leg,this.right_lower_leg_angle,this.right_lower_leg_up);
        rotate(this.left_foot,this.left_foot_angle,this.left_foot_up);
        rotate(this.right_foot,this.right_foot_angle,this.right_foot_up);

        const neckPos = point_in_ball(centerPos,this.angle,this.up + Math.PI * 0.5,this.neck_dist);
        const headPos = point_in_ball(neckPos,this.angle,this.up + Math.PI * 0.5,this.head_dist);
        const left_shoulder_pos = point_in_ball(neckPos,this.angle - Math.PI * 0.5,0,this.shoulder_dist);
        const right_shoulder_pos = point_in_ball(neckPos,this.angle + Math.PI * 0.5,0,this.shoulder_dist);
        const left_upper_arm_pos = point_in_ball(left_shoulder_pos,this.left_upper_arm_angle,this.left_upper_arm_up,this.upper_arm_dist);
        const right_upper_arm_pos = point_in_ball(right_shoulder_pos,this.right_upper_arm_angle,this.right_upper_arm_up,this.upper_arm_dist);
        const left_lower_arm_pos = point_in_ball(left_upper_arm_pos.add(point_in_ball(Origin,this.left_upper_arm_angle,this.left_upper_arm_up,this.upper_arm_dist)),this.left_lower_arm_angle,this.left_lower_arm_up,this.lower_arm_dist);
        const right_lower_arm_pos = point_in_ball(right_upper_arm_pos.add(point_in_ball(Origin,this.right_upper_arm_angle,this.right_upper_arm_up,this.upper_arm_dist)),this.right_lower_arm_angle,this.right_lower_arm_up,this.lower_arm_dist);
        const left_hand_pos = point_in_ball(left_lower_arm_pos.add(point_in_ball(Origin,this.left_lower_arm_angle,this.left_lower_arm_up,this.lower_arm_dist)),this.left_hand_angle,this.left_hand_up,this.hand_dist);
        const right_hand_pos = point_in_ball(right_lower_arm_pos.add(point_in_ball(Origin,this.right_lower_arm_angle,this.right_lower_arm_up,this.lower_arm_dist)),this.right_hand_angle,this.right_hand_up,this.hand_dist);
        const hipsPos = point_in_ball(centerPos,this.angle,this.up + Math.PI * 0.5,-this.hips_dist);
        const left_ass_pos = point_in_ball(hipsPos,this.angle - Math.PI * 0.5,0,this.ass_dist);
        const right_ass_pos = point_in_ball(hipsPos,this.angle + Math.PI * 0.5,0,this.ass_dist);
        const left_upper_leg_pos = point_in_ball(left_ass_pos,this.left_upper_leg_angle,this.left_upper_leg_up,this.upper_leg_dist);
        const right_upper_leg_pos = point_in_ball(right_ass_pos,this.right_upper_leg_angle,this.right_upper_leg_up,this.upper_leg_dist);
        const left_lower_leg_pos = point_in_ball(left_upper_leg_pos.add(point_in_ball(Origin,this.left_upper_leg_angle,this.left_upper_leg_up,this.upper_leg_dist)),this.left_lower_leg_angle,this.left_lower_leg_up,this.lower_leg_dist);
        const right_lower_leg_pos = point_in_ball(right_upper_leg_pos.add(point_in_ball(Origin,this.right_upper_leg_angle,this.right_upper_leg_up,this.upper_leg_dist)),this.right_lower_leg_angle,this.right_lower_leg_up,this.lower_leg_dist);
        const left_foot_pos = point_in_ball(left_lower_leg_pos.add(point_in_ball(Origin,this.left_lower_leg_angle,this.left_lower_leg_up,this.lower_leg_dist)),this.left_foot_angle,this.left_foot_up,this.foot_dist);
        const right_foot_pos = point_in_ball(right_lower_leg_pos.add(point_in_ball(Origin,this.right_lower_leg_angle,this.right_lower_leg_up,this.lower_leg_dist)),this.right_foot_angle,this.right_foot_up,this.foot_dist);

        check(this.body,centerPos);
        check(this.head,headPos);
        check(this.left_upper_arm,left_upper_arm_pos);
        check(this.right_upper_arm,right_upper_arm_pos);
        check(this.left_lower_arm,left_lower_arm_pos);
        check(this.right_lower_arm,right_lower_arm_pos);
        check(this.left_hand,left_hand_pos);
        check(this.right_hand,right_hand_pos);
        check(this.left_upper_leg,left_upper_leg_pos);
        check(this.right_upper_leg,right_upper_leg_pos);
        check(this.left_lower_leg,left_lower_leg_pos);
        check(this.right_lower_leg,right_lower_leg_pos);
        check(this.left_foot,left_foot_pos);
        check(this.right_foot,right_foot_pos);
    }
    destroy(){
        for(const e of this.parts){
            e.destroy();
        }
    }
}
function rotate(entity,angle,up){
    entity.meshOrientation = Quat.rotateX(up).rotateY(angle);
}
function check(entity,pos){
    if(entity.position.distance(pos) > 0.01){
        entity.position.copy(pos);
    }
}
function point_in_ball(origin,angle,up,radius){
    return new Box3Vector3(
        origin.x + Math.cos(angle) * Math.cos(up) * radius,
        origin.y + Math.sin(up) * radius,
        origin.z + Math.sin(angle) * Math.cos(up) * radius
    )
}
function create(mesh,meshScale){
    return world.createEntity({
        mesh,
        meshScale,
        gravity: false,
        collides: false,
    })
}
global.check = check;
global.rotate_ = rotate;
global.point_in_ball = point_in_ball;
module.exports = People;

用法:先构建个People()

参数一个对象()

参数是mesh和radius还有scale()

模型要拆开()

注意四肢要朝前()

不要下垂()

拆之前把人物动作摆成电摇那样()

巴拉巴拉angle和up都能改()

不过每帧要调一下它的update()

如果你做的怪要每帧setVelocity()

里面velocity填碰撞箱的速度(我一般都写碰撞箱)()()()

 

一般是没问题的()

除非你家网卡()

具体效果去结界看()


回复

上一页1 页 / 共 1下一页
迷失冷光迷失冷光

你们要的话我发结界评论区()

点赞0


评论


Robot一只屑代码师Robot一只屑代码师

沙发()

点赞0


评论


HIM_PETERHIM_PETER

前排()

点赞0


评论


屑阿鱼屑阿鱼

沙发【

点赞0


评论


屑胶原蛋屑胶原蛋

6666()

点赞0


评论


风火年华4512风火年华4512

笑死我一行都看不懂()()

点赞0


评论


爱摸鱼的屑胡桃爱摸鱼的屑胡桃

咋用在模型上,这里都没有填模型的地方emotion_编程猫_冷漠

点赞0


评论


Dreamland_AuroraDreamland_Aurora

冷光用不用Shift+Alt+f()

我觉得这个组合键挺好用()

打开编辑器后使用!

点赞0


评论


散落秋枫散落秋枫

第一眼:骨骼()

点赞0


评论


𝙲ℴ𝗌𝔦𝒹ₑ𝑟𝙲ℴ𝗌𝔦𝒹ₑ𝑟

建议结构赋值()

点赞0


评论


𝙲ℴ𝗌𝔦𝒹ₑ𝑟𝙲ℴ𝗌𝔦𝒹ₑ𝑟

还有()你用class extend不开刂不行口马()

点赞0


评论


busterbuster

雾草))这个东西是不是肝了两天半( ))

但是看上去好复杂,,还是感觉星雪的好用( )( )

点赞0


评论


𝙲ℴ𝗌𝔦𝒹ₑ𝑟𝙲ℴ𝗌𝔦𝒹ₑ𝑟

这边建议

class guy extends box喵layerEntity

点赞0


评论


微风御火微风御火

太棒力!一个都看不懂

点赞1


评论


被遗忘的屑被遗忘的屑

class People {
    Clean (entity, speed = 0.1) { // 旋转
        (entity.direction < 0) && (entity.direction = Math.PI * 2 + entity.direction);
        (entity.angle < 0) && (entity.angle = Math.PI * 2 + entity.angle, entity.angle %= Math.PI * 2);
        (Math.min(Math.abs(entity.direction - entity.angle), Math.abs(Math.PI * 2 - entity.direction + entity.angle)) < speed) ? (entity.angle = entity.direction) : (entity.direction > entity.angle) ? (entity.direction - entity.angle < Math.PI ? entity.angle += speed : entity.angle -= speed) : (entity.direction + (Math.PI * 2 - entity.angle) < Math.PI ? entity.angle += speed : entity.angle -= speed);
    }


    constructor (count) {
        this.angle = 0;
        this.AnGle = { angle: 0 };
        this.direction = this.AnGle.direction = Math.atan2(direction.z, direction.x); 
        if (count % 11 === 0) {
            let target = world.querySelectorAll('player').sort((a, b) => {
                return a.position.distance(this.position) - b.position.distance(this.position);
            })[0]; if (target && target.hp != 0) this.target = target;
        };
        if (this.target && !this.target.destroyed) {
            var direction = this.target.position.sub(this.position); 
            var speed = 0.4 + Math.random() * 1;
            this.Clean(this); this.Clean(this.AnGle, 0.3);
            this.velocity.set(Math.cos(this.angle) * Math.cos(0) * speed, -Math.sin(0) * speed, Math.sin(this.angle) * Math.cos(0) * speed);
        };
    }
};

给顶吗()

旋转追踪更加丝滑(

点赞0


评论