I apologize if there is already a thread on this (though I’ve scoured quite good I think).
I’ve been all through the network example and have learned quite a bit (at least I feel like I have :). However, much to my dismay, I’ve been unsuccessful in getting shooting to work.
Currently I have players able to join just fine, they walk around great, however shooting seems to be quite the trick. Every time the mouse is pushed on any of the machines, everyone fires
kinda fun, but not obviously intentional.
I’m assuming I should be using RPC’s (as I get an error when using Network.Instantiate() saying that Rigidbody isn’t ideal for this, which seems required to make the shots move…)
The way I understand it, is the RPC’s need to have a Network View attached to the objects as well.
The script is attached to an object that is invisible that has a Network View(observing this script). The Shot also has a network view attached to it (observing the shot’s transform).
var projectile : Rigidbody;
var initialSpeed = 90.0;
var reloadTime = 0.5;
private var lastShot = -10.0;
function Update(){
if (Input.GetButton ("Fire1")){
if (Time.time > reloadTime + lastShot) {
lastShot = Time.time;
networkView.RPC("Fire", RPCMode.AllBuffered);
}
}
}
@RPC
function Fire () {
// create the shot
var newProjectile : Rigidbody;
newProjectile = Instantiate (projectile, transform.position, transform.rotation);
// give it force
newProjectile.velocity = transform.TransformDirection(Vector3 (0, 0, initialSpeed));
// Ignore collisions between the missile and the character controller
Physics.IgnoreCollision(newProjectile.collider, transform.root.collider);
Physics.IgnoreCollision(newProjectile.collider, transform.parent.collider);
}
I know for sure there is something I’m not grasping but any explanations or help would be awesome (even if it’s broad)
Great forums and thanks in advance ![]()