Hello,
I’m trying to get my projectile to fire on my network game (being a client or server). And I don’t actually know the best way to do this, I don’t think I’m doing it correct at all.
Whats happening right now, is if I fire on the server, my character fires fine but the clients also fire, but in an upward direction (its top down). If I fire on the clients side, you see the projectile fire out of everyones gun for a split second, then it disappears.
I’m trying to get to grips with the RPC, I think I see one of my problem, but again, I don’t even know if this is the correct way to do it.
This is my gun script:
#pragma strict
var muzzleShot : Transform;
var paintballRound : Rigidbody;
function Update () {
if(GameObject.FindWithTag("Player")){
if (Input.GetButtonDown("Fire1")) {
if(networkView.isMine){
Fire();
}
else{
var viewID = Network.AllocateViewID();
networkView.RPC("SendFire", RPCMode.AllBuffered, viewID, muzzleShot.transform.position, muzzleShot.transform.rotation); //viewID
}
}
}
}
function Fire(){
var clone : Rigidbody;
clone = Instantiate(paintballRound, muzzleShot.transform.position, muzzleShot.transform.rotation);
//clone = Network.Instantiate(paintballRound, muzzleShot.transform.position, muzzleShot.transform.rotation, 0);
Physics.IgnoreCollision(clone.collider, GameObject.FindWithTag("Player").collider);
clone.velocity = transform.TransformDirection (Vector3.forward * 10);
}
@RPC
function SendFire(viewID : NetworkViewID, location : Vector3, rotate : Quaternion){
var clone : Transform;
clone = Instantiate(paintballRound, location, rotate.identity) as Transform;
var nView : NetworkView;
nView = clone.GetComponent(NetworkView);
nView.viewID = viewID;
}
So whats it saying it, if the network is mine (I’m the player), fire a normal projectile NOT using the network, else if you are a client (viewing the person shooting), then also fire a projectile < this is why I believe the projectiles fire upwards on the client, because it isn’t spawning it at the tip of the players gun, nor shooting in the right direction.
Please help me out, I’ve been stuck on this for days. Once I get this, I’ll be able to get on my way!
Thanks all.