用户:
全能代码师查看:11 回复:30 评论:11 创建时间:2022-01-03T13:56:24
/*友情声明:本代码为Lolita原创!在这里我只是转载!如果要使用代码,请标明原作者Lolita!*/
function drive1(entity) {
let angle1 = entity.direction;
if (angle1 < 0) {
angle1 = PI2 + angle1;
}
if (entity.angle < 0) {
entity.angle = PI2 + entity.angle;
}
entity.angle %= PI2;
const angle2 = entity.angle;
if (Math.min(Math.abs(angle1 - angle2), Math.abs(PI2 - angle1 + angle2)) < 0.1) {
entity.angle = entity.direction;
return undefined;
} else {
if (angle1 > angle2) {
if (angle1 - angle2 < Math.PI) {
entity.angle += 0.1;
return 0;
} else {
entity.angle -= 0.1;
return 1;
}
} else {
if (angle1 + (PI2 - angle2) < Math.PI) {
entity.angle += 0.1;
return 0;
} else {
entity.angle -= 0.1;
return 1;
}
}
}
}
const PI2 = Math.PI * 2
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),
});
plane.angle = 0;//玩家视角角度
plane.direction = 0;
plane.rotateX = 0;
entity.plane = plane;
planes.push(plane)
entity.up = 0;
plane.speed = 1;//自己调整速度
plane.rotateZ = 0;
plane.angle = Math.atan2(entity.player.facingDirection.z,entity.player.facingDirection.x);
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
}
}
if (entity.player.crouchButton == true) {
if (entity.up < 0.8) {
entity.up += 0.1
}
}
plane.direction = Math.atan2(entity.player.facingDirection.z, entity.player.facingDirection.x)
const num = drive1(plane);
if (num === 1) {//右
if (plane.rotateZ < 1) {//在这段代码中,-1和1为飞机转弯系数,系数越大能力越好
plane.rotateZ += 0.1
} else {
plane.rotateZ = 1;
}
} else if (num === 0) {//左
if (plane.rotateZ > -1) {
plane.rotateZ -= 0.1
} else {
plane.rotateZ = -1;
}
} else if (num == undefined) {
plane.rotateZ *= 0.95;
}
plane.velocity.set(Math.cos(plane.angle) * Math.cos(entity.up) * plane.speed, -Math.sin(entity.up) * plane.speed, Math.sin(plane.angle) * Math.cos(entity.up) * plane.speed);
plane.meshOrientation = plane_Quat.rotateY(Math.PI * 0.5).rotateZ(plane.rotateZ).rotateX(-entity.up).rotateY(plane.angle);
}
墨染云天imgsrc="https://static.codemao.cn/emoji/codemao/%E7%BC%96%E7%A8%8B%E7%8C%AB_%E7%82%B9%E8%B5%9E.gif"alt="emotion_编程猫_点赞"
点赞0
评论
https://box3.codemao.cn/e/eb9e4e25ffaaa775c436?p=lnfpWJ喵LSE04C4U0A2PD0KlmELlwXIOAQEn0WiLmA7qf9CyoMAVndWVzdA%3D%3D
点赞0
评论
https://box3.codemao.cn/e/eb9e4e25ffaaa775c436?p=YJ9WYAQOiTlfVr%2BsD%2FFUUJm7ZSzVYYbwUNg7UbdRIaA7zNhi2oMAbnvJbovpE%3D
点赞0
评论