- Home /
all players spinning[Photon]
In a previous thread I was creating a spin function for my character. Well, it was a success! As long as my player is standing still, the other client sees just fine and is un-affected.
if (IsGrounded())
{
if(Input.GetKey(KeyCode.Alpha1)){
this.transform.Rotate (Vector3.up, sSpeed * Time.deltaTime);
if(sSpeed<1000)
sSpeed+=1.0f;
}
else
transform.rotation = Quaternion.LookRotation(moveDirection);
}
else
{
Vector3 xzMove = velocity;
xzMove.y = 0;
if (xzMove.sqrMagnitude > 0.001f)
{
transform.rotation = Quaternion.LookRotation(xzMove);
}
}
When I add the spin function to the movement adjustment, all players on the current client begin to rotate
if (IsGrounded())
{
if(Input.GetKey(KeyCode.Alpha1)){
this.transform.Rotate (Vector3.up, sSpeed * Time.deltaTime);
if(sSpeed<1000)
sSpeed+=1.0f;
}
else
transform.rotation = Quaternion.LookRotation(moveDirection);
}
else
{
if(Input.GetKey(KeyCode.Alpha1)){
this.transform.Rotate (Vector3.up, sSpeed * Time.deltaTime);
if(sSpeed<1000)
sSpeed+=1.0f;
}
else{
Vector3 xzMove = velocity;
xzMove.y = 0;
if (xzMove.sqrMagnitude > 0.001f)
{
transform.rotation = Quaternion.LookRotation(xzMove);
}
}
}
I think I need to make a rpc function for the spin... The above code works fine while the player is standing still... Its when he moves that causes the problem. I'm thinking its more about where I added code for him moving rather than the rpc as this file is constantly being updated by photon.
Is this the right track¿
adding
if(Input.Get$$anonymous$$ey($$anonymous$$eyCode.Alpha1 && **isControllable**)){
this.transform.Rotate (Vector3.up, sSpeed * Time.deltaTime);
if(sSpeed<1000)
sSpeed+=1.0f;
}
else{
Vector3 xz$$anonymous$$ove = velocity;
xz$$anonymous$$ove.y = 0;
if (xz$$anonymous$$ove.sqr$$anonymous$$agnitude > 0.001f)
{
transform.rotation = Quaternion.LookRotation(xz$$anonymous$$ove);
}
}
was unaffective
Answer by iwaldrop · Dec 24, 2013 at 11:22 PM
You need to check the PhotonView's isMine property. It just so happens a Google search pulled up this question I answered previously.
Essentially, only do the rotation/movement if it is yours. Other players should see the result after applying the updated information that is received in the OnPhotonSerializeView method.
Your answer
Follow this Question
Related Questions
More efficient way to call these RPC's (Code works) 1 Answer
Proper way to instantiate projectile in PUN 1 Answer
Update int value with photon rpc? 0 Answers
Info on Photon PUN RPC calls. 0 Answers
Photon synchronization on different devices failes 0 Answers