Simple question: let client move game object.

This is what I want to happen: I have randomly spawned objects. I want each player to be able to interact with the objects by clicking on them and then clicking somewhere else to throw them.

I have all of that working for several days now in single player. I’m using Raycasts for detection. I have zero issues.

The problem is multiplayer. I cannot get my client to interact at all. The host works fine, but the client will not interact with anything that has a NetworkTransform on it.

I have tried ClientRpc, ServerRpc, sending lists, sending everything, spawning and despawning things over and over, clientnetworktransforms, so on.

I figured I would get the answer eventually, but I have not. For something so seemingly simple it is driving me up a wall. As I was writing this post, I thought I should try moving the player object (which is currently mostly an empty object), and yes, it took two seconds, put a script on it, just worked. Why can’t I move other objects like that as well?

Short version: How the hell do I move objects on a client with raycast?

Either:

  • Client authoritative movement: Use ClientNetworkTransform > check for IsOwner > do the raycast and move
  • Server authoritative movment: Use NetworkTransform > check for IsOwner > do raycast > send result position of raycast to server using a ServerRpc > move on server

I understand the concept, but it is not working for me, and that is where the issue lies.

I have a script that checks if a user is the host, and if so spawns a pair of objects.

if (IsServer && IsLocalPlayer)
                {
                    var purple = Instantiate(pieceSpawn.CreatePiece(), new Vector3(7.5f, .5f, 0f), Quaternion.identity);
                    var blue = Instantiate(pieceSpawn.CreatePieceDown(), new Vector3(7.5f, 7.5f, 0f), Quaternion.identity);
                 
                    purple.GetComponent<NetworkObject>().Spawn();
                    blue.GetComponent<NetworkObject>().Spawn();

                }

Then I do a pair of raycasts to select one of those objects, and if have one selected, move it to the new point.

  if (Input.GetMouseButtonDown(0))
        {
            hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);

            if (hit.collider != null && !hit.collider.CompareTag("Board"))
            {
          
                selected = hit.collider.gameObject;
            }
            else if (hit.collider != null && selected != null && hit.collider.CompareTag("Board"))
            {
             
                {
                    selected.transform.position = hit.transform.position;
              
                }
     
            }

        }

The movement does not work on a client. It works perfectly fine on a host, but no matter what I do I cannot get the movement to work. I have used networktransforms, clientnetworktransforms, (isowner), [serverrpc], [serverrpc(requireownership = false)], a [serverrpc] that calls a [clientrpc]. I have also tried different ways to movement, from translate to otherwise, but I don’t think that is the problem, since even in edit mode, if I try to manually edit the values, it simply does not work.