[SOLVED] Other player rotation not seen by player

I have This script for network here:

var Network = pc.createScript('network');

Network.attributes.add('gamePlayManagerEntity', {type: 'entity'});


// static variables
Network.id = null;
Network.socket = null;

// initialize code called once per entity
Network.prototype.initialize = function() {
    // this.player = this.app.root.findByName('Player');
    // this.other = this.app.root.findByName('Other');
    
    this.player = this.gamePlayManagerEntity.script.gamePlayManagerScript.playerEntity;
    this.other = this.gamePlayManagerEntity.script.gamePlayManagerScript.otherEntity;
    
    // var socket = io.connect('https://playcanvas-multiplayer.glitch.me'); // Glitch hosted server
    var socket = io.connect('https://playcanvas-mp.glitch.me'); // Glitch hosted server
    Network.socket = socket;
    
    // socket.emit ('initialize');
    var nicknameVal = this.player.findByName('playerNickText').element.text;
    socket.emit ('initialize',{nicknameVal: nicknameVal});
    
    // this.displaySendMsg();
    
    var self = this;
    socket.on ('playerData', function (data) {
        self.initializePlayers (data);
    });

    socket.on ('playerJoined', function (data) {
        self.addPlayer(data);
    });

    socket.on ('playerMoved', function (data) {
        self.movePlayer(data);
    });
    
    socket.on ('playerSendMsg', function (data) {
        self.displaySendMsg(data);
    });

    socket.on ('killPlayer', function (data) {
        self.removePlayer(data);
    });
    
};

Network.prototype.initializePlayers = function (data) {
    this.players = data.players;
    Network.id = data.id;

    for(var id in this.players){
        if(id != Network.id){
            this.players[id].entity = this.createPlayerEntity(this.players[id]);
        }
    }
    
    this.initialized = true;
    console.log('initialized');
};

Network.prototype.addPlayer = function (data) {
    this.players[data.id] = data;
    this.players[data.id].entity = this.createPlayerEntity(data);
};

Network.prototype.movePlayer = function (data) {
    if (this.initialized && !this.players[data.id].deleted) {
        this.players[data.id].entity.rigidbody.teleport(data.x, data.y, data.z);
    }
};

Network.prototype.removePlayer = function (data) {
    if (this.players[data].entity) {
        this.players[data].entity.destroy ();
        this.players[data].deleted = true;
    }
};

Network.prototype.createPlayerEntity = function (data) {
    var newPlayer = this.other.clone();
    newPlayer.enabled = true;

    this.other.getParent().addChild(newPlayer);

    if (data)
    {
        newPlayer.rigidbody.teleport(data.x, data.y, data.z);
        newPlayer.findByName('otherNickText').element.text = data.nicknameVal;
    }

    return newPlayer;
};

// update code called every frame
Network.prototype.update = function(dt) {
    this.updatePosition();
};

Network.prototype.updatePosition = function () {
    if (this.initialized) {
        var pos = this.player.getPosition();
        Network.socket.emit('positionUpdate', {id: Network.id, x: pos.x, y: pos.y, z: pos.z});
    }
};




Network.prototype.sendMsg = function (nicknameVal, actualMsg) {
    this.displaySendMsg({id: Network.id, nicknameVal:nicknameVal, actualMsg:actualMsg});
    Network.socket.emit('sendMsgToAll', {id: Network.id, nicknameVal:nicknameVal, actualMsg:actualMsg});
    // console.log("sendMsg = ",{id: Network.id, nicknameVal:nicknameVal, actualMsg:actualMsg});
};

Network.prototype.displaySendMsg = function (data) {
    
    // console.log(data);
    if(data.nicknameVal !== "" && data.actualMsg !== "")
    {
        this.gamePlayManagerEntity.script.gamePlayManagerScript.addMsgInChatBox(data.nicknameVal,data.actualMsg);
    }
};



But I tried to add rotation to display to both players but * failed.* what did I do wrong?

Hi @Jacob_Mcbride! I have expand the original multiplayer example project with rotation. If I remember well the player also look at the mouse position. If you are be able to apply this to your project we can solve two topics at once.

https://playcanvas.com/project/827020/overview/custom-multiplayer

3 Likes

Oh MY GOD! You are officially the best GUY ON PLAYCANVAS EVER!!! :smiley: :smiley: :smiley: :heart_eyes: :heart_eyes:

1 Like

Mind if I add you to my project? I will need your username, but your the best, and I NEED your help.

It doesn’t make sense to add me. I don’t want to change anything in your project, because I can break things with this.

What problem do you have when using network.js from my example project?

I added an fps script and the face is an entity child of the camera, yet the rotation and position are not seen by the other players. why? here’s the editor: https://playcanvas.com/editor/scene/1344331

Can you implement the same structure of this into my game? (Can you fork my game and add your script, share it with me, and I fix my game?) The editor for my MAIN project is here:https://playcanvas.com/editor/scene/1338583

Wait. Why you add a FPS script? Does my example has a FPS script? Are you making two games at the moment?

1 Like

funny story, yes I was tinkering with your project, I added an fps script to it, and Yes I was doing two games at once, but I need help with my main one here: https://playcanvas.com/editor/scene/1338583

I understand you want to create a game and I’m happy to help you with that, sinds I started the same way, but if you can’t code yourself you definitely can’t make two games at once.

Sinds you already use the network.js script in your original project my network.js script should work in your project too. You probably only have to change some minor things, that’s why I ask you what problem you have.

1 Like

I am not trying to make two games, I wanted to use the rotation thing for my game.
And I need the rotation to be seen here: https://playcanvas.com/editor/scene/1338583
for a more engageing game.

I need other players rotation to be seen by all players as well as the hands rotation.

I understand what you need. As far I have seen you use the same network.js script as I use in my example project. In this project I also sent the rotation to the network and because of that the other player can see the correct rotation. Did you try to replace your network.js code with my network.js code?

No, but I am not sure that my project will function correctly if I do so, will it?
Here is the editor: https://playcanvas.com/editor/scene/1338583

If you don’t try you don’t know. You can make a backup checkpoint first.

Okay. thanks again, and I AM going to add you as admin so you can help me there, and we can talk through the chat.

Sorry, I’m unable to do that because I’m on mobile most of the time. I only can help you here.

1 Like

Oh jeez, that’s sad. well, I can make you read and write so you can code. And I can chat through the editor chat with you.

No @Jacob_Mcbride. I can’t use the editor on mobile. Try yourself and share your problems.

1 Like

Oh, okay well we can always chat here and fix problems!

1 Like