猫史档案馆


【每日一个岛3建图小技巧】超实用教程,变成模型+自定义出生点

用户:神岛吉吉喵神岛吉吉喵查看:22 回复:42 评论:22 创建时间:2021-04-04T17:34:49


有不少同学都在问的代码教程来咯!

分别是让自己变成模型的样子

以及自定义出生点!

1.变成模型

https://www.bilibili.com/video/BV1DV411n7gm

视频中用到的代码:

for (const e of world.querySelectorAll('*')) {
    e.collides = true //实体可以被碰撞
    e.fixed = true //实体固定位置
    e.onEntityContact(({ other }) => {
        if (other.isPlayer) { // 如果跟当前实体碰撞的是玩家实体
            e.destroy()  //当前实体消失
            other.player.invisible = true // 玩家皮肤隐藏
            other.mesh = e.mesh // 玩家的外形换成当前实体的外形
            other.meshScale.copy(e.meshScale) // 玩家外形的缩放比例设成跟当前实体一样
            other.player.scale = e.meshScale.scale(e.bounds.y / other.bounds.y) //喵家的隐形碰撞盒缩放到模型刚好贴地
        }
    })
}

如果模型的朝向有问题

那么就要修正一下方向:

const Quat = new Box3Quaternion(0, 0, 0, 1)
for (const e of world.querySelectorAll('*')) {
    e.collides = true
    e.fixed = true
    e.onEntityContact(({ other }) => {
        if (other.isPlayer) { // 如果跟当前实体碰撞的是玩家实体
            other.player.invisible = true // 玩家皮肤隐藏
            other.mesh = e.mesh // 玩家的外形换成当前实体的外形
            other.meshScale.copy(e.meshScale) // 玩家外形的缩放比例设成跟当前实体一样

            //如果模型方向不正确, 则建议在模型编辑器里把模型转向修正

            // 也可以尝试下面其中一行代码, 但不同的模型需要转的角度不同, 无法通用
            // other.meshOrientation = Quat.rotateY(Math.PI) // 如果模型方向不对, 尝试旋转180度来修正, Math.PI是180度的弧度值
            // other.meshOrientation = Quat.rotateY(Math.PI/2) // 如果模型方向不对, 尝试旋转90度来修正
            // other.meshOrientation = Quat.rotateY(-Math.PI/2) // 如果模型方向不对, 尝试旋转-90度来修正

            other.player.scale = e.meshScale.scale(e.bounds.y / other.bounds.y) //喵家的隐形碰撞盒缩放到模型刚好贴地
        }
    })
}

2.自定义出生点

https://www.bilibili.com/video/BV1g喵y1S768

在某个坐标出生的4种写法:  

world.onPlayerJoin(({entity})=>{
    entity.player.spawnPoint.set(4, 11, 4)
    entity.player.forceRespawn()
})
world.onPlayerJoin(({entity})=>{
    entity.player.spawnPoint.set(4, 11, 4)
    entity.position.copy(entity.player.spawnPoint)
})
world.onPlayerJoin(({entity})=>{
    entity.player.spawnPoint = new Box3Vector3(4, 11, 4)
    entity.player.forceRespawn()
})
world.onPlayerJoin(({entity})=>{
    entity.player.spawnPoint = new Box3Vector3(4, 11, 4)
    entity.position.copy(entity.player.spawnPoint)
})

在某个模型的位置出生:

world.onPlayerJoin(({entity})=>{
    entity.player.spawnPoint = world.querySelector('#出生点').position
    entity.position.copy(entity.player.spawnPoint)
    entity.position.y += 10
})

开发API文档:https://docs.box3.codemao.cn/

加入代码岛3.0官方内测Q喵

官网:box3.codemao.cn

下面的二维码会扫出来什么呢?( =•ω•= )m

center_image


回复

上一页1 页 / 共 2下一页
Architect_皮卡awaArchitect_皮卡awa

sofa

点赞0


评论


Architect_皮卡awaArchitect_皮卡awa

板凳!

点赞0


评论


Architect_皮卡awaArchitect_皮卡awa

嗷呜嗷呜~

点赞0


评论


传说云(已退)传说云(已退)

板凳

点赞0


评论


神兽喵神兽喵

前排

点赞0


评论


Architect_皮卡awaArchitect_皮卡awa

吉吉喵的沙发真香~

(原声:哎呀~妈呀~真香~)

点赞0


评论


指令者指令者

前排

点赞0


评论


面了了了条面了了了条

前排

点赞0


评论


亿只懒Ink亿只懒Ink

前排

点赞0


评论


小树同学小树同学

椅子

点赞0


评论


凌_墨水凌_墨水

前排

点赞0


评论


蔡宁进(大家再见)蔡宁进(大家再见)

呵呵,吉吉喵的朴实无华加强版……

点赞0


评论


async_functionasync_function

前排

点赞0


评论


SKQASKQA

喵是啥

点赞0


评论


面具狐狸云绾兮面具狐狸云绾兮

前排()

点赞0


评论


面具狐狸云绾兮面具狐狸云绾兮

什么时候出如何将多个模型联动()

(就多个长方体的模型能像蛇一样的代码())

点赞0


评论


我是谁我在哪我在干啥我是谁我在哪我在干啥

希望官方能出个能得编程猫皮肤的活动

点赞2


评论


大无敌大无敌

谢了,我正愁不会做。

点赞0


评论


jlmbcjlmbc

本周玩儿什么,这周有吗

点赞0


评论


Chengxuyee_已退Chengxuyee_已退

那怎么还原玩家模型呢?

点赞1


评论


编码喵编码喵

#include <iostream>
using namespace std;

int main(){
  cout<<"厉害👍"<<endl;
  return 0;
}

点赞0


评论


编码喵编码喵

window.alert("沙发");

点赞0


评论


喝不明液体的钉三多喝不明液体的钉三多

  nice~

点赞0


评论


IaeaIaea

666

点赞0


评论


蔡宁进(大家再见)蔡宁进(大家再见)

11

点赞0


评论


爱笑的赤星芽芽牛爱笑的赤星芽芽牛

谢了

点赞0


评论


难起的名字难起的名字

考古()

点赞0


评论


温柔的飓风雀h_nM温柔的飓风雀h_nM

考古

点赞0


评论


温柔的飓风雀h_nM温柔的飓风雀h_nM

勇闯无人区

点赞0


评论


屑student屑student

怎么让玩家还原成原来的形状a

点赞0


评论