How to spawn projectiles on the server from a client.
I will start this post by saying that I have spent the past week googling to find answers and I am still stuck. I am a student developing a multiplayer FPS using UNET for a project. Because of the complexity of the systems in my game I find it hard to explain but here it goes;
I want to instantiate a projectile object that moves straight forward. This is code that is in a script on the player object for instantiating the prefab for the effect;
[Command]
public void CmdSpawnBall() {
shockDir = transform.InverseTransformDirection(mainCamera.transform.forward);
GameObject shock = Instantiate(shockBall, this.shockPoint.position, this.shockPoint.rotation) as GameObject;
ShockBall ball = shock.GetComponent<ShockBall>();
ball.dir = shockDir;
ball.damage = EXPLOSION_DAMAGE;
ball.root = wc.gameObject;
NetworkServer.Spawn(shock);
}
and here is the update function for my ShockBall class;
void Update () {
transform.Translate(dir * Time.deltaTime * speed);
}
I build and run two instances of the game, the localhost and localclient. If i fire the projectile from the localhost, it works as it should on both the host and the client. Whereas if I fire the projectile from the client, it is visible in the host instance but not the client from which it was fired. Also the projectile does not move, which I believe is because of the client side prefab not being instantiated so the update function is not called.
If anyone would like more information or code from my project please let me know :)
I have the same problem and I've been stuck on this for the past week and I'm a student too :( Did you figure out what's going on and if you did could you please share the answer