用户:
阳光的流熔怪Uyt5查看:7 回复:24 评论:7 创建时间:2022-03-10T00:15:04


//by 路人
//使用时请注明作者
console.clear()
obj = world.querySelector('#翅膀')
const ENTITY_QUAT = new Box3Quaternion(0, 0, 0, 1)
async function rotate(entity, t = 0, l = 1) {//代码报错的速度是秒速5厘米!
entity.bounds = new Box3Vector3(1, 1, 3)
entity.meshOrientation = entity.meshOrientation.rotateZ(t)
while (true) {
for (let i = 0; i <= 45; i++) {
entity.rotate = l * (Math.PI / 180 * i * 1.3)
await sleep(5)
}
for (let i = 45; i >= 0; i--) {
entity.rotate = l * (Math.PI / 180 * i * 1.3)
await sleep(5)
}
}
}
function asin(k) {
return Math.asin(k) / Math.PI * 2
}
async function move(entity, entity1, pos, pos1) {
entity.spos = new Box3Vector3(pos1.x - pos.x, pos1.y - pos.y, pos1.z - pos.z)
//转化为原点到spos的角
//压缩到xz平面上
entity.db = entity.spos.z//对边
entity.xb = Math.sqrt((entity.spos.z) * (entity.spos.z) + (entity.spos.x) * (entity.spos.x))
entity.meshOffset = new Box3Vector3(0, 0, 1.8)
entity1.meshOffset = new Box3Vector3(0, 0, 1.8)
if (entity.spos.x >= 0) {//喵码警告
if (entity.db / entity.xb >= 0) {
entity.meshOrientation = ENTITY_QUAT.rotateY(Math.asin(entity.db / entity.xb)).rotateX(-1 * entity.rotate * asin(entity.db / entity.xb)).rotateZ(entity.rotate * (1 - asin(entity.db / entity.xb)))
entity1.meshOrientation = ENTITY_QUAT.rotateY(-Math.asin(entity.db / entity.xb)).rotateZ(Math.PI).rotateX(entity.rotate * asin(entity.db / entity.xb)).rotateZ(-1 * entity.rotate * (1 - asin(entity.db / entity.xb)))
}
else {
entity.meshOrientation = ENTITY_QUAT.rotateY(Math.asin(entity.db / entity.xb)).rotateX(entity.rotate * (asin(-entity.db / entity.xb))).rotateZ(entity.rotate * (1 - asin(-entity.db / entity.xb)))
entity1.meshOrientation = ENTITY_QUAT.rotateY(-Math.asin(entity.db / entity.xb)).rotateZ(Math.PI).rotateX(-1 * entity.rotate * (asin(-entity.db / entity.xb))).rotateZ(-1 * entity.rotate * (1 - asin(-entity.db / entity.xb)))
}
}
else {//哈哈,啊哈哈哈哈哈哈————bug来咯——————
if (entity.db / entity.xb >= 0) {
entity.meshOrientation = ENTITY_QUAT.rotateY(-Math.asin(entity.db / entity.xb) + Math.PI).rotateX(-1 * entity.rotate * asin(entity.db / entity.xb)).rotateZ(-1 * entity.rotate * (1 - asin(entity.db / entity.xb)))
entity1.meshOrientation = ENTITY_QUAT.rotateY(Math.asin(entity.db / entity.xb) + Math.PI).rotateZ(Math.PI).rotateX(entity.rotate * asin(entity.db / entity.xb)).rotateZ(entity.rotate * (1 - asin(entity.db / entity.xb)))
}
else {
entity.meshOrientation = ENTITY_QUAT.rotateY(-Math.asin(entity.db / entity.xb) + Math.PI).rotateX(entity.rotate * asin(-entity.db / entity.xb)).rotateZ(-1 * entity.rotate * (1 - asin(-entity.db / entity.xb)))
entity1.meshOrientation = ENTITY_QUAT.rotateY(Math.asin(entity.db / entity.xb) + Math.PI).rotateZ(Math.PI).rotateX(-1 * entity.rotate * asin(-entity.db / entity.xb)).rotateZ(entity.rotate * (1 - asin(-entity.db / entity.xb)))
}
}
}
async function createWay(obj, obj1, seedx, seedy) {//代码比较喵,建议当模块使用
obj.x = Math.sin(seedx / 114 * 514 / 4) * 32 + Math.cos(seedy / 810 * 1919) * 32 + 喵//生成较为平滑的随机数 好臭啊
obj.y = 12 + Math.sin(seedx / 404 * 505) * 3
obj.z = Math.cos(seedx / 996 * 1024) * 32 + Math.sin(seedy / 1919 * 1680) * 32 + 喵
move(obj, obj1, obj.position, new Box3Vector3(obj.x, obj.y, obj.z))
obj.position = new Box3Vector3(obj.x, obj.y, obj.z)
obj1.position = new Box3Vector3(obj.x, obj.y, obj.z)
//我们仍未知道那天所见bug的名字
}
async function fly(obj, obj1) {//Tips:你调试蓝了 你调试红了 你调试没了
obj.meshEmissive = 1
obj.meshShininess = 1
obj.meshColor = new Box3RGBAColor(1, 1, 0, 1)
obj1.meshEmissive = 1
obj1.meshShininess = 1
obj1.meshColor = new Box3RGBAColor(1, 1, 0, 1)
obj.meshOrientation = ENTITY_QUAT
obj1.meshOrientation = ENTITY_QUAT
rotate(obj)
rotate(obj1, Math.PI, -1)
obj.seedx = Math.random() * Math.PI * 2
obj.seedy = Math.random() * Math.PI * 2
while (true) {
createWay(obj, obj1, obj.seedx, obj.seedy)
obj.seedx += 0.001
obj.seedy -= 0.001
await sleep(10)
}
}
async function addFly() {
for (let i = 0; i < 40; i++) {
left = world.createEntity(obj)
right = world.createEntity(obj)
fly(left, right)
// await sleep(1000)
}
}
addFly()
代码费了我七天功夫,应该是最后的作品了
模型文件在过审,更新代码和模型会在置顶发
墨染云天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
评论