- Home /
Question by
osybear · Apr 28, 2017 at 05:47 AM ·
networkingsynchronization
Object Spawning has a delay when connected client is moving
Why does my object spawning have a delay?
I have the host , and then the client connected to the host making that 2 players. Both players have a weapon to shoot a bullet. Everytime my second player is moving and shooting the bullets transform position at instantiation is delayed and not actually at the position it should be. Anyway to fix this?
Code of how I handle object spawning
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class GunScript : NetworkBehaviour {
private GameObject GuntipGO;
public GameObject BulletPrefab;
// Use this for initialization
void Start () {
GuntipGO = transform.Find("FirstPersonCharacter").Find("Gun").Find("GunTip").gameObject;
}
// Update is called once per frame
void Update()
{
if (!isLocalPlayer)
{
return;
}
PlayerInput();
}
private void PlayerInput()
{
if(Input.GetMouseButtonDown(0))
{
SpawnBullet();
}
}
//[Command]
//private void CmdSpawnBullet()
private void SpawnBullet()
{
GameObject clone = Instantiate(BulletPrefab,GuntipGO.transform.position, GuntipGO.transform.rotation);
NetworkServer.SpawnWithClientAuthority(clone,gameObject);
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612120717im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Photon Unity Networking (Viking Demo) Error: Argument is out of range. 1 Answer
Synvar hook firing but value not getting updated on client 0 Answers
How to display connections count on client 4 Answers
Frame skipped when WebRequest.Create() is called for the first time 1 Answer
How to synchronize Datetime from server to client? 0 Answers