Local Multiplayer Basic shooting
Hello fellow people of the Unity community... I have set up a local multiplayer game. I have now started trying to make a shooting component. So far I have the bullet to be able to spawn (on all the players screens). Now comes the problem, the bullets are shot forward on the player who shot its side but they don't fly forward on the other players sides. It also only shows the bullets the host shoots? Thanks in advance: using System.Collections; using System.Collections.Generic; using UnityEngine;
public class earthshote : MonoBehaviour
{
public Rigidbody Earthshote;
private float fireStart = 0f;
private float fireCooldown = 0.1f;
public float speed = 30;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetButton("Earth1"))
{
if (Time.time > fireStart + fireCooldown)
{
fireStart = Time.time;
Rigidbody instantiatedProjectile = Network.Instantiate(Earthshote, transform.position, transform.rotation, 0) as Rigidbody;
Network.Instantiate(Earthshote, transform.position, transform.rotation, 0);
instantiatedProjectile.velocity = transform.TransformDirection (Vector3.forward * speed);
}
}
}
}
Answer by metalted · Feb 27, 2017 at 11:16 PM
Lets start with this. I have never used the Unity Networking API. For making online games I mostly use Photon Networking, its free, lots of tutorials and demo scenes, check it out.
If you are making a local multiplayer game, why are you using Networking? You could just create it like a single player game and add a character with its own controls and own camera. This takes the whole networking out of the equation. Takes some time to get the whole splitscreen and controls working but hey, its local multiplayer so no lag and no need for fancy network code.
The way it has been coded (the way i have it doing the multiplayer) it doesn't work like that as its basically a network etc as my end goal is a online project. I did try a normal shoot and it doesn't work. Also it does show the spawning on the other players computer but doesn't add the velocity. Also its not split screen. Its separate computers. Though thanks for your reply
I think i found your answer here: http://answers.unity3d.com/questions/199637/add-force-to-bullet-in-the-network.html
wait so how would i re code it? sorry for being slow