- Home /
Desync between host and client.
My character spawns a bullet object when it fires. The bullet then uses Rigidbody.AddForce()
to move. This is inside the Start()
method of the BulletController.
I have used "parent" to mean the GameObject that instantiated the bullet, which isn't a feature that works because I cannot set the parent object before the Start method runs. (I assume Start runs on instantiation not spawn, which causes more than enough problems).
void Start()
{
Physics.gravity = new Vector3(0f, 0f, -9.81f);
Vector3 parentVelocity = parent.GetComponent<Rigidbody>().velocity;
Vector3 bulletVelocity = parentVelocity + (transform.forward * -thrust);
GetComponent<Rigidbody>().AddForce(transform.forward * -thrust);
Destroy(gameObject, 5);
camera = GameObject.Find("Main Camera");
transform.position = transform.position + -transform.forward;
}
My spawn code:
GameObject projectile = (GameObject)Instantiate(bullet, transform.position, transform.rotation);
projectile.GetComponent<bulletController>().parent = gameObject; //Set the parent
NetworkServer.Spawn(projectile);
The problem, is that it is only spawning on the host, and not the client.
Your answer
Follow this Question
Related Questions
C# destroy gameobject with tag 5 Answers
c# - Rename Instatiated GameObject - Solved 2 Answers
(C#)Place GameObject from Mouse 0 Answers
Why does IsSleeping() keep returning false? (Billiard Logic) 0 Answers
Distribute terrain in zones 3 Answers