用户:
白水WhiteWater点猫账号专门发帖查看:0 回复:0 评论:0 创建时间:2023-03-01T15:05:58
world.onPlayerJoin(({ entity }) => {//当玩家进入时
const originPlayerMesh = entity.mesh;//玩家
world.onInteract(({ entity, targetEntity }) => {
if (targetEntity.mesh.match("p") != 0) {
entity.mesh = targetEntity.mesh;//玩家模型变成车
entity.meshScale = targetEntity.meshScale;//大小一致
entity.meshOrientation = targetEntity.meshOrientation;
entity.position = targetEntity.position;//位置
targetEntity.destroy();//原来的车销毁
entity.player.invisible = true;
entity.player.showName = false;
entity.player.canFly=true;
entity.enableInteract = false;
}
});
///上车
world.onPress(({ button, raycast }) => {
if (button === 'crouch') {
const origincar = entity;
//车
world.createEntity({
id: "p",
mesh: origincar.mesh,
mass: origincar.mass,
friction: origincar.friction,
position: origincar.position,
meshScale: origincar.meshScale,
restitution: origincar.restitution,
meshOrientation: origincar.meshOrientation,
collides: true,
gravity: true,
fixed: true,
})
//world.createEntity(car);
entity.mesh = originPlayerMesh
entity.player.invisible = false;//人物变为原来 注意顺序
entity.player.showName = true;
entity.player.canFly=false;
}
})
})
world.onEntityCreate(({ entity }) => {//此时的entity的模型为载具
if (entity.mesh.match("p") != 0) {
//console.log("是车");
entity.enableInteract = true; // 开启实体互动功能
entity.interactRadius = 8; // 互动范围大小
}
})