用户:
LOUISQII查看:7 回复:1 评论:7 创建时间:2023-07-27T12:28:42
如何让玩家触碰实体传送至指定位置
如何让玩家触碰实体传送至指定位置
如何让玩家触碰实体传送至指定位置
如何让玩家触碰实体传送至指定位置
有用的我会给他的所有作品三连加关注
快乐的流星喵djhy先检测玩家碰到实体:
world.onEntityContact()这个是在world世界的物理相关一栏,自己找一下
world.onEntityContact()
事件
当实体与实体发生碰撞时触发。
● onEntityContact: Box3EventChannel<Box3EntityContactEvent>
● nextEntityContact: Box3EventFuture<Box3EntityContactEvent>
返回值 Box3EntityContactEvent:{ entity, other, force, axis, tick }
名称 类型 说明
entity Box3Entity 碰撞中的第一个实体
other Box3Entity 碰撞中的第二个实体
force Box3Vector3 碰撞所产生的力
axis Box3Vector3 碰撞后物体弹飞的方向
tick number 事件发生时间
简单示例
/* 两个实体进行碰撞时,广播一条消息 */
world.onEntityContact(({ entity, other }) => {
const entityA = entity.isPlayer ? entity.player.name : entity.id;
const entityB = other.isPlayer ? other.player.name : other.id;
world.say(`${entityA}和${entityB}发生了激烈的碰撞`)
});
碰到指定实体加血
/* 玩家碰到包含 'healpoint' 标签的实体,回复全部HP */
world.onEntityContact(({ entity, other }) => {
if (!entity.isPlayer || !other.hasTag('healpoint')) return;
if (entity.hp < entity.maxHp) { // 恢复全部HP
entity.hp = entity.maxHp;
entity.player.directMessage('你回复了全部的HP');
}
});
碰到实体变身
/* 玩家碰到实体时,将自身变成实体的造型 */
world.onEntityContact(({ entity, other }) => {
if (entity.isPlayer && !other.isPlayer) {
fakeObject(entity, other);
}
});
function fakeObject(player, object) {
player.mesh = object.mesh;
player.meshOrientation = object.meshOrientation;
player.meshScale = object.meshScale;
player.player.showName = false;
}
💡提示
两个实体刚接触的第一下,触发onEntityContact 直到两个实体分开,触发onEntitySeparate
传送的话,看下如下代码:
entity.position.set(x,y,z)
这里的xyz分别指要传送的坐标,在代码里填数字,例:
entity.position.set(61,94,46)点赞0
评论