FPS Multiplayer joined player rotation not visible

I was trying First-Person with multiplayer using photon but there I can’t see any type of rotation for other players joining I tried updating the rotation of the player in the player.js script too here is my code and project link PlayCanvas | HTML5 Game Engine. Any support is appreciated. I am very new in this thing trying new stuff:slightly_smiling_face:.

var Player = pc.createScript('player');

Player.prototype.initialize = function () {
    if (!this.app.loadBalancing || !this.app.loadBalancing.isJoinedToRoom()) {
        console.error("not connected");
    }
    this.tmpVec = this.entity.getPosition().clone();
    this.tmpVec1 = this.entity.getRotation().clone();
    this.app.on("loadbalancing:raiseEvent", this.raiseEvent, this);
};

Player.prototype.postUpdate = function () {
    const playerPos = this.entity.getPosition();
    const playerRot = this.entity.getRotation();
    if (!this.tmpVec.equals(playerPos)) {
        this.tmpVec = playerPos.clone();
        this.raiseEvent();
    }

    if (!this.tmpVec1.equals(playerRot)) {
        this.tmpVec1 = playerRot.clone();
        this.raiseEventI();
    }
};

Player.prototype.raiseEvent = function () {
    if (!this.tmpVec.x || !this.tmpVec.y || !this.tmpVec.z) return;
    const data = {
        position: {
            x: this.tmpVec.x,
            y: this.tmpVec.y,
            z: this.tmpVec.z,
        }

        
    };

    
    console.log("raiseEvent!!");
    this.app.loadBalancing.raiseEvent(0, data);
};

Player.prototype.raiseEventI = function () {
   

        if (!this.tmpVec1.x || !this.tmpVec1.y || !this.tmpVec1.z) return;
    const data1 = {
        rotation: {
            x: this.tmpVec1.x,
            y: this.tmpVec1.y,
            z: this.tmpVec1.z,
        }
};
console.log("raiseEventI!!");
    this.app.loadBalancing.raiseEventI(0, data1);
};

Hi @sid-k,

One thing I would try, instead of raising a second event just for the rotation, I’d send the rotation together with the position event (so a single event per update).

If we are talking about humanoid characters walking around and just looking left/right, you may get away with sending the rotation around the Y axis (a single number).

When you receive the message on each remote player’s listener and you appl the position, there you can also apply the rotation around Y to the player model.

Hope that helps.

1 Like

Hey @Leonidas I think i tried what you said its not working can you check whats wrong? and here is my script is this correct

var Player = pc.createScript('player');

Player.prototype.initialize = function () {
    if (!this.app.loadBalancing || !this.app.loadBalancing.isJoinedToRoom()) {
        console.error("not connected");
    }
    this.tmpVec = this.entity.getPosition().clone();
    this.tmpVec1 = this.entity.getRotation().clone();
    this.app.on("loadbalancing:raiseEvent", this.raiseEvent, this);
};

Player.prototype.postUpdate = function () {
    const playerPos = this.entity.getPosition();
    const playerRot = this.entity.getRotation();


    if (!this.tmpVec.equals(playerPos)) {
        this.tmpVec = playerPos.clone();
        this.raiseEvent();
    }

    if (!this.tmpVec1.equals(playerRot)) {
        this.tmpVec1 = playerRot.clone();
        this.raiseEvent();
    }
};

Player.prototype.raiseEvent = function () {
    if (!this.tmpVec.x || !this.tmpVec.y || !this.tmpVec.z) return;
    const data = {
        position: {
            x: this.tmpVec.x,
            y: this.tmpVec.y,
            z: this.tmpVec.z,
        }
        
    };

    if (!this.tmpVec1.y) return;
    const data1 = {
        rotation: {
            y: this.tmpVec1.y,
        }
};
    console.log("raiseEvent!!");
    this.app.loadBalancing.raiseEvent(0, data);
    this.app.loadBalancing.raiseEvent(1, data1);
    
};

my project link PlayCanvas | HTML5 Game Engine