Moving and rotating other players' avatars #3343
Replies: 2 comments
-
As a temporary workaround, I've had the custom client subscribe to a new data channel and publish move messages to it: https://github.com/hackerspace-zone/art/blob/main/meeting-button.js In the NAF.connection.subscribeToDataChannel("player_move", (sender,type,detail,target) => {
this.el.sceneEl.emit("player_move", detail);
});
this.el.sceneEl.addEventListener('player_move', (evt) => {
const detail = evt.detail;
if (detail.clientId != NAF.clientId)
return;
// Message for us: Get the avatar rig and relocate it
const player = document.querySelectorAll("#avatar-rig")[0];
player.object3D.position.set(detail.position.x, detail.position.y, detail.position.z);
player.object3D.rotation.set(detail.rotation.x, detail.rotation.y, detail.rotation.z);
}); and then in the const players = document.querySelectorAll("a-entity[player-info]");
const num = players.length;
let step = Math.PI * 2 / num;
let angle = 0;
for(p of players)
{
// circle around the position of the box,
// looking at the box, up is the y axis
const player_angle = angle;
angle += step;
NAF.utils.getNetworkedEntity(p).then(player => {
const clientId = NAF.utils.getNetworkOwner(player);
const detail = {
clientId: clientId,
position: {
x: pos.x + r * Math.cos(player_angle),
y: pos.y,
z: pos.z - r * Math.sin(player_angle),
},
rotation: {
x: 0,
y: player_angle + Math.PI,
z: 0,
},
};
if (clientId == NAF.clientId)
this.el.sceneEl.emit("player_move", detail);
else
NAF.connection.broadcastDataGuaranteed("player_move", detail);
});
} It seems that broadcast messages are not received by the clients that send them, so I had to add some hacks to check if the destination was the same as the source, and the Is this the recommended way to create synchronized behaviour for custom components? Or is there a technique that I've missed? |
Beta Was this translation helpful? Give feedback.
-
Are you still having issues with this setup? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to implement an "Emergency Meeting" button in my modified hubs client with custom a-frame components. The goal is to summon all of the current room occupants to a circle around a point when anyone hits the button. The custom component works to move the player who pushes the button, but the position update on the NAF components doesn't move the other players.
The core piece that I've tried is:
(A minor issue is that the rotation also doesn't work for the button pushing player - they are relocated, and rotated, but revert to facing the direction that they were when they pushed the button as soon as they perform any movement)
Is there a way to send a message to all of the other clients to reposition their players and to remotely set their avatars' orientations?
Beta Was this translation helpful? Give feedback.
All reactions