Spawning 2nd part of Player (Tank Turret)

Hallo,

I‘m working on a two parted player. It has a “Base” and a “Turret” like a Tank.

Actually the Base is spawned by the NetworkManager and everything is fine. It can be controlled by the correct client (Network Transform). The Turret is instantiate in the Start() Method of the base. So it’s normal that it won’t be synced.

I don’t know how to spawn the Turret.

I try this steps:

  1. give the Turret Network Identity and Transform
  2. put the Turret in the NetworkManager under Registered Spawnable Prefabs
  3. Idea A and Idea B

Idea A:

void Start () {
    _model = Instantiate(TurretPrefab, transform.position, Quaternion.identity) as GameObject;
    NetworkServer.Spawn(_model);
...
}

Problem A:
On the Host-Client the own Turret moves and rotates.
On the Client every Player got two Turrets and one of each Player moves and rotates.

Idea B:
I moved the Instantiate with a NetworkServer.Spawn in a Command like below

[Command]
private void CmdSpawnTurret()
{
    _model = Instantiate(TurretPrefab, transform.position, Quaternion.identity) as GameObject;
    NetworkServer.Spawn(_model);
}

Problem B:
On the Host-Client the own Turret moves and rotates.
On the Client no one got a Turret and the movement brokes completely.

How and where do I have to spawn the Turret?

Thanks for help :slight_smile:

Are you able to make the turret a child of the base?

If so, set the parent of the turret to the base, save as a prefab, and use that as the player.

You can then add a network transform child component to the base.

The Idea is a good one, but it seems to work not correct.

If I don’t register the Turret in the Registered Spawnable Prefabs, it behaves like without a network transform. The turret just stay on the base. The base is movable.

If I register the Turret, it behaves broken. The Client doesn’t get the Turret and the Host-Client-does.

Thanks Jackevin… I got it :slight_smile:
I was a bit slow. There where dependences I don’t transformed.
Now it works.