用户:
萌新大佬查看:3 回复:5 评论:3 创建时间:2022-06-07T19:54:05
async function fromTo(entity = new Box3Entity, to = new Box3Entity) {
var Quat = new Box3Quaternion(0, 0, 0, 1).rotateZ(Math.PI / 2).rotateX(Math.PI / 2);//初始角度,自行调整
var w = entity.player.addWearable({
mesh: 'mesh/箭头.vb',
offset: new Box3Vector3(0, 1.2, 0),
scale: new Box3Vector3(1 / 3, 1 / 3, 1 / 3),
bodyPart: Box3BodyPart.HEAD,
})//穿戴“箭头”
var t = world.onTick(() => {
var p = entity.position.sub(to.position);
var angle = (
Math.atan2(p.z, p.x)
+
Math.atan2(entity.player.facingDirection.x, entity.player.facingDirection.z)
);//旋转角度
w.orientation = Quat.rotateX(angle);
if (entity.position.distance(to.position) < 2) {//到达终点判断
entity.player.directMessage('已到达');
w.remove();
t.cancel();
}
})
}
entity是玩家,to是目标实体,实现功能为玩家头顶的箭头一直指向目标
(只做了平面,三维可以同理)