用户:
小鹿deer查看:4 回复:3 评论:4 创建时间:2021-12-19T18:16:15
交互开飞机,求代码(不是飞行,是开飞机)
console.clear()
const planes = []
world.onPlayerJoin(({ entity }) => {
const plane = world.createEntity({
mesh: 'mesh/飞机.vb',
collides: true,//碰撞
gravity: false,//重力
position: new Box3Vector3(喵, 喵, 喵),
meshScale: new Box3Vector3(0.02, 0.02, 0.02),
});
entity.plane = plane;
planes.push(plane)
entity.up = 0;
plane.speed = 3;
entity.player.cameraEntity = plane
entity.player.invisible = true;
entity.player.spectator = true;
});
world.onTick(({ tick }) => {
world.querySelectorAll('player').forEach((x) => {
drive(x, x.plane)
})
})
const plane_Quat = new Box3Quaternion(0, 0, 0, 1);
async function drive(entity, plane) {
if (entity.player.jumpButton == true) {
if (entity.up > -0.8) {
entity.up -= 0.1
}
} else if (entity.player.crouchButton == true) {
if (entity.up < 0.8) {
entity.up += 0.1
}
}
plane.meshOrientation = plane_Quat.rotateZ(entity.up).rotateY(Math.atan2(entity.player.facingDirection.z, entity.player.facingDirection.x) + Math.PI / 2)
plane.position.y += -entity.up;
plane.position.x += entity.player.facingDirection.x
plane.position.z += entity.player.facingDirection.z
}点赞0
评论