用户:
小屑鹿查看:5 回复:3 评论:5 创建时间:2023-06-17T10:19:16
——————————————————————————————————————————————————————————————————————————————————————————————————————————————

非常拉垮的风暴AI:
=-=
首先,你需要这样一个模型():

把它命名为storm
然后就可以搬函数力(喜:
const Quat = new Box3Quaternion(0, 0, 0, 1);
async function storm(x, y, z/*x,y,x是坐标*/) {
const storms = []
const basic = world.createEntity({
mesh: "",
position: [x, y, z],
gravity: false,
collides: false,
fixed: true,
})
for (var h = 0; h <= 7; h++) {
const storm = world.createEntity({
id: `${h}`,
mesh: 'mesh/storm.vb',
position: [x, y + h * 1.5, z],
meshOrientation: [0.707, 0.000, 0.000, 0.707],
meshScale: [0.05 + 0.03 * h, 0.05 + 0.03 * h, 1.5],
meshColor: [0.03 + 0.02 * h, 0.03 + 0.02 * h, 0.03 + 0.02 * h, 1],
meshEmissive: 0.05,
gravity: false,
collides: false,
fixed: true,
})
storms.push(storm);
}
world.onTick(({ tick }) => {
let random1 = Math.random()
let random2 = Math.random()
if (tick % 5 == 0) {
let rad = new Box3Vector3(basic.position.x - 1 + random1 * 2, basic.position.y, basic.position.z - 1 + random2 * 2)
let d2 = rad.sub(basic.position)
let dist = d2.mag()
const speed = 0.3
basic.velocity.set(d2.x / dist * speed, d2.y / dist * speed, d2.z / dist * speed)
}
})
for (const str of storms) {
world.onTick(({}) => {
let pos = str.position
pos.x=basic.position.x
pos.z=basic.position.z
world.querySelectorAll('player').forEach(async (e) => {
if (e.position.distance(pos) <= (str.bounds.x + str.bounds.z) / 2) {
e.enableDamage = true
e.hurt(10)
e.velocity.y += 0.05
await sleep(1000)
}
})
})
let Quat = str.meshOrientation
if (Math.floor(str.id / 2) != str.id / 2) {
str.animate([
{ meshOrientation: Quat, duration: 3 },
{ meshOrientation: Quat.rotateY(Math.PI / 2), duration: 3 },
{ meshOrientation: Quat.rotateY(Math.PI), duration: 3 },
{ meshOrientation: Quat.rotateY(-Math.PI / 2), duration: 3 },
], {
duration: 50,
iterations: Infinity,
direction: Box3AnimationDirection.WRAP,
});
} else if (Math.floor(str.id / 2) == str.id / 2) {
str.animate([
{ meshOrientation: Quat, duration: 3 },
{ meshOrientation: Quat.rotateY(Math.PI / 2), duration: 3 },
{ meshOrientation: Quat.rotateY(Math.PI), duration: 3 },
{ meshOrientation: Quat.rotateY(-Math.PI / 2), duration: 3 },
], {
duration: 50,
iterations: Infinity,
direction: Box3AnimationDirection.WRAP_REVERSE,
});
}
}
}
![]()