How do I rotate a Networked gameobject on spawn?
In my game I have players aim with their mouse and shoot rockets. The host has their rockets fire in the right direction but all clients rockets just stay and 0 rotation.
The code to shoot-
void Cmd_shoot(){
GameObject rock = Instantiate(rockket, firePoint.transform.position, Quaternion.identity) as GameObject;
rock.GetComponent<rocketBehavior> ().rotation = gunRot;
NetworkServer.Spawn (rock);
}
the rocket's code when instantiated-
[SyncVar]
public Quaternion rotation;
// Use this for initialization
void Start () {
cc = this.GetComponent<Rigidbody2D> ();
this.transform.rotation = rotation;
cc.AddForce (transform.up * 60f);
}
This works 100% fine as the host but I'm not sure how to make it work for the client?
I looked around previously and had found people were using syncvars to communicate rotation, so that's why I tried it here. Doesn't seem to be working and I can't seem to find any answers.
Your answer
Follow this Question
Related Questions
Problem with instantiating and declaring objects in Netcode on client 0 Answers
Networking - How do i spawn an object with client authority? 1 Answer
Gameobjects spawn differently on client and host. 0 Answers
Instantiate works only in Editor 0 Answers
The thing i want to instantiate is null? 0 Answers