how to move photon object using raycast to different multiplayer position??

Options
Hi..
Hope u are doing well
I am working on 2D multiplayer board game.
There is box which is moving toward hited photon instantiate object.
But my game is like own player should be in centre and other player should be in either left or right.
For this i am doing like this.

I have doest not attached observed component to spanwend(destination) player. So they can stay there.

if(photonView.isMine)
{
transform.tag = "MyPlayer";
transform.position = GameObject.Find("5_pos").transform.position;
}
else
{
// photonView.RPC("changePos",PhotonTargets.All,null);
GameObject[] otherplayers = new GameObject[6];
for(int i = 0; i < 6; i++)
{
otherplayers[i] = GameObject.FindGameObjectWithTag("s");
Debug.Log(otherplayers[0].transform.name);
}
otherplayers[0].transform.position = GameObject.Find("1_pos").transform.position;
otherplayers[1].transform.position = GameObject.Find("2_pos").transform.position;
otherplayers[2].transform.position = GameObject.Find("3_pos").transform.position;
otherplayers[3].transform.position = GameObject.Find("4_pos").transform.position;
otherplayers[4].transform.position = GameObject.Find("6_pos").transform.position;
}

And Raycasting like this for movement ::
void Update ()
{
MaxPlayerDisply.text = "Connected Player :"+PhotonNetwork.countOfPlayers;
if (Input.GetMouseButtonUp (0))
{
hit = Physics2D.Raycast (Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector3.zero);
Debug.Log("mouse up");
if (hit.collider != null && hit.collider.gameObject.name.Contains("Player"))
{
int viewID = hit.transform.root.GetComponent().viewID;
Debug.Log("id"+viewID);
GameObject.Find("TestText").GetComponent().text = ""+viewID;
photonView.RPC("transferbox",PhotonTargets.All,viewID);
}
}
}
[PunRPC]
void transferbox(int id)
{
Debug.Log("transferbox rpc called"+PhotonView.Find(id).gameObject.transform.position);
GameObject.Find("box(Clone)").transform.position = Vector2.MoveTowards(GameObject.Find("box(Clone)").transform.position,PhotonView.Find(id).gameObject.transform.position, 50);
}

Box is going successfully to spawned palyer but doest not reflact in network :
I want to do something like this. Please take a look to attached game play image




expecting help . Please provide any logic or code for this..


Best Answer

  • Allough
    Allough
    Answer ✓
    Options
    This is actually a Unity3D question I believe, but here goes.

    The board and pieces should all have the same world position no matter which player is viewing them. The thing that is unique per player is that players game camera. In your example, the boxes/players are all in the same positions relative to each other and the world.

    You don't want the objects to have different positions in the world based on the camera, you want the camera itself to have a different position based on the player.

Answers

  • Allough
    Allough
    Answer ✓
    Options
    This is actually a Unity3D question I believe, but here goes.

    The board and pieces should all have the same world position no matter which player is viewing them. The thing that is unique per player is that players game camera. In your example, the boxes/players are all in the same positions relative to each other and the world.

    You don't want the objects to have different positions in the world based on the camera, you want the camera itself to have a different position based on the player.