用户:
治愈绾兮查看:23 回复:13 评论:23 创建时间:2021-08-01T13:06:34
制作过山车,说白了就是玩家移动(这句话是宅宅说的),因此,我们可以用position.set让玩家不断移动到过山车轨道上。
首先,我们需要建一个过山车轨道,并且按照过山车移动的顺序给轨道从1到n命名;
然后,开始写代码。
代码第一步:设置坐过山车的条件,这里假设在玩家进入地图时坐过山车1圈,那么代码框架就是:
world.onPlayerJoin(async ({ entity }) => {
});
代码第二步:如果要让玩家不断移动到下一个轨道上,就需要让玩家自己不能动,并且不受重力影响,如果用canFly是不行的,因为飞行打开的话玩家是可以控制自己飞不飞的,因此,需要设置玩家为幽灵模式,并且为了让他自己不能动,要把飞行速度和加速度调为0,也就是:
world.onPlayerJoin(async ({ entity }) => {
entity.player.spectator = true;
entity.player.flySpeed = 0;
entity.player.flyAcceleration = 0;
})
然后,就是重点,要让玩家不断移动到下一个轨道上,其实并不难,直接看代码:
world.onPlayerJoin(async ({ entity }) => {
entity.player.spectator = true;
entity.player.flySpeed = 0;
entity.player.flyAcceleration = 0;
for (let i = 1; i <= 100; i++) {//这里的100表示有100个轨道,可以自行调整
entity.position.set(world.querySelector("#" + String(i)).position.x, world.querySelector("#" + String(i)).position.y + 2, world.querySelector("#" + String(i)).position.z)
await sleep(100)
}
})
最后,重置玩家的数据:
world.onPlayerJoin(async ({ entity }) => {
entity.player.spectator = true;
entity.player.flySpeed = 0;
entity.player.flyAcceleration = 0;
for (let i = 1; i <= 100; i++) {
entity.position.set(world.querySelector("#" + String(i)).position.x, world.querySelector("#" + String(i)).position.y + 2, world.querySelector("#" + String(i)).position.z)
await sleep(100)
}
await sleep(1000)//这里的等待1秒是为了让玩家坐完过山车后等1秒再下车
entity.player.spectator = false;
entity.player.flySpeed = 2;
entity.player.flyAcceleration = 2;
entity.position.set(喵, 10, 喵)//这是坐完过山车后要去的位置,可以自行调整
})
好了,以上就是全部代码,下面是白嫖时间:
world.onPlayerJoin(async ({ entity }) => {
entity.player.spectator = true;
entity.player.flySpeed = 0;
entity.player.flyAcceleration = 0;
for (let i = 1; i <= 100; i++) {
entity.position.set(world.querySelector("#" + String(i)).position.x, world.querySelector("#" + String(i)).position.y + 2, world.querySelector("#" + String(i)).position.z)
await sleep(100)
}
await sleep(1000)
entity.player.spectator = false;
entity.player.flySpeed = 2;
entity.player.flyAcceleration = 2;
entity.position.set(喵, 10, 喵)
})
小提示,轨道之间间距越短,间距越均匀,效果越好。