My project: PlayCanvas 3D HTML5 Game Engine
So far I fixed it so the the player’s position is set server-sided and synced. But how would I do this with the box object so that you can see when a different player is moving or spinning the box?
My project: PlayCanvas 3D HTML5 Game Engine
So far I fixed it so the the player’s position is set server-sided and synced. But how would I do this with the box object so that you can see when a different player is moving or spinning the box?
I fixed it so the box can technically move around, but only one person can push it and it flickers whenever it moves.
Hi @Literally_Kirby!
I think the problem is that you use setLocalPosition
on an entity with a dynamic rigidbody. Because of this, only the entity is moved while the rigidbody is not. Instead you need to use rigidbody.teleport
.
https://developer.playcanvas.com/en/user-manual/physics/physics-basics/#teleporting-dynamic-bodies
and how would i do this with rotation?
You can add the rotation as well.
entity.rigidbody.teleport(pos, rot);
entity.rigidbody.teleport(posX, posY, posZ, rotX, rotY, rotZ);
and this method would work in photon?
Yes, why not? Not sure about performance.
I tried to do this but now the box just disappears, the scripts are boxlocation and photon load balancing btw
You still use setPosition
.
otherPlayer.setPosition(position, rotation);
In that line you should use teleport
.
otherPlayer.rigidbody.teleport(position, rotation);
Apart from that, I think you need to use getEulerAngles()
instead of getRotation()
to get the correct rotation, but I’m not sure.
the box still disappears when ever the second player joins the game
How is joining of a second player be related to those functions?
Maybe because then it’s starting sharing the location. Unfortunately, I don’t have a lot of experience with Photon and multiplayer games in general.
I have no idea
discovery: first getting position was only logging the function defination might be a playcanvas bug or because the box is a child of the environment entity. Second, when I switched to this.entity.getLocalPosition() it was working fine untill the second player joined.
Maybe you van try to only update the position on collision, to see if that works.
This sounds like you were logging getPosition / getLocalPosition instead of getPosition() / getLocalPosition() . If you don’t execute the function, its definition is logged as opposed to the value it returns.
nope, didnt work
What is the result?
it disappears again