Moving the game avatar around

Options
I have a setup where the game avatar is just a camera with the interest area in front of it to look from a top down at the world. I have code that moves the camera in relation to dragging (via mouse) on the screen, this works but of course just moving the transform around does not let the server know where you have moved. So i tried game.avatar.MoveAbsolute and this is not working out at all.

I currently have both moveabsolute happening and transform moving. I dont feel this is the right approach any advice would be great.


public float dragSpeed = 2; private Vector3 dragOrigin; private Game game; private RunBehaviour runBehaviour; void Start() { runBehaviour = GameObject.Find("Scripts").GetComponent<RunBehaviour>(); game = runBehaviour.Game; } void Update() { if (Input.GetMouseButtonDown(0)) { dragOrigin = Input.mousePosition; return; } if (!Input.GetMouseButton(0)) return; Vector3 pos = Camera.main.ScreenToViewportPoint(Input.mousePosition - dragOrigin); Vector move = new Vector(pos.x * dragSpeed, pos.y * dragSpeed); Vector3 move3 = new Vector3(pos.x * dragSpeed, 0, pos.y * dragSpeed); game.Avatar.MoveAbsolute(move, game.Avatar.Rotation); //Vector3 move = new Vector3(pos.x * dragSpeed, 0, pos.y * dragSpeed); transform.Translate(move3, Space.World);

Comments

  • Hi @Tanahara,

    I'm currently not sure why you want the camera to be synchronized. Do all players share the same view? In this case the camera object needs to implement the IPunObservable interface, where you can send and receive the current position. In case the camera should not be controlled by anyone at the same time, it requires a PhotonView component, too, where you have the possibility to limit the 'control access'. Synchronization can also be done, by only adding a PhotonView and PhotonTransformView component to the camera game object and setting them up correctly in the editor.