[SOLVED] Multiplayer rotation with PlayCanvas and Photon

@Alexis_Shaju you have it mostly correct. The capsule based FPS player that is the real thing that is moving uses physics. So it’s direction is controlled by applying force. Inside the player capsule is the camera which the mouse controls is rotation and the up/down angle. But… the camera rotates inside the player and does not physically rotate the rigid body itself. So the data we are sending from each player in player.js is x,y, and z position. And then we use the camera rotation to capture what the player is looking at. These are the important items we send.

In the game room we are just feeding the clones in the view of the actual player data from the other players in the room.

Thank you for this explanation. It made it a lot clearer.

1 Like

@Tirk182
Is it possible to manually select for example the two arms and the head, and set both their x and y rotations using the same method? So that when the player looks up and down, their arms and head do the same, to simulate real game rotations.

@Alexis_Shaju Yes this is possible. For this to look natural you would have to work with some more animations. You already have the rotation eulers.x and can easily pass the eulers.y by adding it to you passed data in player.js. Handling this you will have to search for animations for all the movements or maybe you could create using Blender.

@Tirk182 What animations exactly have to be made? I’m just getting basic movement from Mixamo and applying it to my enemy swat model.

Do you mean in particular the extreme points that both the head and arm can rotate? And is this do-able through blender?

@Alexis_Shaju I use Mixamo but have no idea as to all the animations they have. So do they have a look left/right? Head up or down? If they don’t you may have to adjust the armature points manually or mix up your own in blender. Here is an example from forum.

State graph animation speeds and linking bones during animation - PlayCanvas Office Hours #2 - YouTube

State graph animation speeds and linking bones during animation - Help & Support - PlayCanvas Discussion

@Albertos
Not doing this is coming back to haunt me now.
So does this teleport, move the rigidbody of the enemy players, so that they can be recognised by the viewing player?

@Tirk182 Any suggestions on what I should be teleport here, so that the rigidbody of the player moves?

I assume it’s done in the game-room.js.

The method you need to use depends on the rigidbody type you use.

What is the rigidbody type you use and what is the problem you have at the moment?

We have a dynamic rigidbody, another person in my group has implemented first person shooting.
Now I need to work to make that multiplayer. The logic I have shows you what you hit with your bullet, whether it is a box on the ground or air etc. When I shoot at the player, it shows that I have shot air.

The raycast is not detecting the rigidbody of the player which I am trying to shoot.

It doesn’t matter what kind of player movement you use. If this is a dynamic rigidbody then you can use applyForce() and teleport() for this. It depends on how you apply the positions and rotations in your multiplayer network system. If you use for example setPosition() here, you have to make sure you create a different player entity for your connected players that has a kinematic rigidbody.

If you currently have only one player entity with a dynamic rigidbody and you use this for the connected payers too, then you need to use teleport() in your mulitplayer network system.

So what I understand, is you have two “enemy” player entities, one using setPosition and the other with a kinematic rigidbody that uses applyForce and teleport?

No, you can have one player entity that has a dynamic rigidbody and use applyForce() and teleport() for it and you have one enemy entity that has a kinematic rigidbody and use setPosition() for it.

This doesn’t seem to work, maybe I am implementing it wrong.
The first person player, has a dynamic rigidbody along with other things. The enemy model template, now has a kinematic rigidbody attached to it.

In my logic handling, this enemy template’s position is set using setPosition.

That seems to be correct to me. Maybe there is another problem? Can I see your project please?

I am working on a branch right now. I will commit everything to master and send you a link.

https://playcanvas.com/editor/scene/1628329

Here is the link to the current state of the game. The playermodel in the corner of the screen, pistol idle, is the enemy player model, which is created upon player created.

The problem here is that the enemy player has no collision component.

The use of mesh collision, as you now use for your player, is also not recommended. This is very bad for performance. Better use a primitive like a capsule.

So would I just use a collision capsule component the size of my model? Would this be best?

I tried this, at it does not seem to be the problem. I added a collision to enemy player aswell.