Question by
mntoyi · Nov 09, 2020 at 12:55 PM ·
networkingtransformmultiplayerphotonmultiplayer-networking
[PHOTON] Transform not synching correctly
Hey guys! Wonder if you could help me with this, I'm stuck and don't know what to do. I'm trying to make a 1vs1 bomberman game with a kick/throw bomb mechanic, the thing is that when playerA puts a bomb and kick it, it shows fine on both clients, but when playerB tries to return it, you can see the bomb going back on playerB screen but not on playerA. The bomb is spawned with
PhotonNetwork.Instantiate("Bomb", position, Quaternion.identity);
and has its PhotonView and TransformView attached. The player and bomb movement are tile based and made by Coroutines. Here's a video showing the issue.
Here's the Player's kick code:
private void ProcessActionInput()
{
if(Input.GetKeyDown(KeyCode.X))
{
RaycastHit2D hit = Physics2D.Raycast(transform.position, currentDirection, 2.0f, isBomb);
if (hit)
{
Bomb bomb = hit.transform.GetComponent<Bomb>();
if (bomb != null)
bomb.StartCoroutine(bomb.MoveBomb(currentDirection));
}
else return;
}
}
And the Bomb move Coroutine:
public IEnumerator MoveBomb(Vector3 direction)
{
coll.enabled = false;
IsMoving = true;
float elapsedTime = 0.0f;
float distance = 0.0f;
float bombSpeed = 0.0f;
bool canJump = false;
origPos = transform.position;
Vector3 jumpDistance = origPos + direction;
RaycastHit2D hit = Physics2D.Raycast(origPos, direction, 11.0f, canPhase);
if(hit)
{
if (direction == Vector3.up)
{
distance = Mathf.Abs(origPos.y - hit.transform.position.y);
targetPos = new Vector3(origPos.x, hit.transform.position.y - 1.0f, origPos.z);
}
else if (direction == Vector3.down)
{
distance = Mathf.Abs(origPos.y - hit.transform.position.y);
targetPos = new Vector3(origPos.x, hit.transform.position.y + 1.0f, origPos.z);
}
else if (direction == Vector3.right)
{
distance = Mathf.Abs(origPos.x - hit.transform.position.x);
targetPos = new Vector3(hit.transform.position.x - 1.0f, origPos.y, origPos.z);
}
else if (direction == Vector3.left)
{
distance = Mathf.Abs(origPos.x - hit.transform.position.x);
targetPos = new Vector3(hit.transform.position.x + 1.0f, origPos.y, origPos.z);
}
bombSpeed = distance / 8;
}
if(distance <= 1.0f)
{
Collider2D occupiedTile;
distance = 0.0f;
while (distance < 11.0f)
{
occupiedTile = Physics2D.OverlapCircle(jumpDistance, 0.25f, canJumpInto);
if (occupiedTile != null)
{
distance += 1.0f;
jumpDistance = origPos + (direction * distance);
if (occupiedTile.gameObject.CompareTag("Boundary"))
{
canJump = false;
break;
}
}
else
{
canJump = true;
break;
}
}
if (canJump)
{
if (direction == Vector3.up)
targetPos = new Vector3(origPos.x, origPos.y + distance, origPos.z);
else if (direction == Vector3.down)
targetPos = new Vector3(origPos.x, origPos.y - distance, origPos.z);
else if (direction == Vector3.right)
targetPos = new Vector3(origPos.x + distance, origPos.y, origPos.z);
else
targetPos = new Vector3(origPos.x - distance, origPos.y, origPos.z);
bombSpeed = distance / 8;
}
else
{
coll.enabled = true;
IsMoving = false;
yield break;
}
}
coll.enabled = true;
while (elapsedTime < 1.0f)
{
transform.position = Vector3.Lerp(origPos, targetPos, elapsedTime);
elapsedTime += (Time.deltaTime / bombSpeed);
yield return null;
}
transform.position = targetPos;
yield return null;
IsMoving = false;
}
`
Comment