SO i was trying to figure out this scripting for multiplayer shooting. i have been working off of the multiplayer shooting tutorial and for some reason when i start up the server and i have the host and a separate client, the host can move around and shoot in any direction but the client can only shoot straight, regardless of my camera positioning. was just trying to figure out how to shoot my bullet the direction its facing. Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Networking; using UnityStandardAssets.Characters.FirstPerson; public class PlayerNetwork : NetworkBehaviour { public GameObject FPSCamera; public CharacterController characterController; public FirstPersonController fpsController; public GameObject bulletPrefab; public Transform bulletSpawn; private Transform playerTransform; // Player Position Vars [SyncVar] private Vector3 syncPosition; public float movementLerpRate = 15; //Player Rotation vars [SyncVar] private Quaternion syncPlayerRotation; public float rotationLerpRate = 15; void Start() { playerTransform = GetComponent<Transform>(); if (!isLocalPlayer) { FPSCamera.SetActive(true); characterController.enabled = false; fpsController.enabled = false; } } // This [Command] code is called on the Client … // … but it is run on the Server! [Command] void CmdFire() { // Create the Bullet from the Bullet Prefab var bullet = (GameObject)Instantiate( bulletPrefab, bulletSpawn.position, bulletSpawn.rotation); // Add velocity to the bullet bullet.GetComponent<Rigidbody>().velocity = bullet.transform.forward * 6; // Spawn the bullet on the Clients NetworkServer.Spawn(bullet); // Destroy the bullet after 2 seconds Destroy(bullet, 2.0f); } public void LeaveServer() { Debug.Log("Leaving server" + Time.timeSinceLevelLoad); Network.Disconnect(); } public override void OnStartLocalPlayer() { GetComponentInChildren<Camera>().enabled = true; } public void Update() { if (!isLocalPlayer) { return; } if (Input.GetButtonDown("Fire1")) { CmdFire(); GetComponentInChildren<Animation>().Play("PistolShoot"); } } private void FixedUpdate() { LerpPosition(); SendPosition(); LerpRotation(); SendRotation(); } private void LerpPosition() { if (!isLocalPlayer) { playerTransform.position = Vector3.Lerp(playerTransform.position, syncPosition, Time.deltaTime * movementLerpRate); } } [Command] private void CmdProvidePosToServer(Vector3 position) { syncPosition = position; } [ClientCallback] private void SendPosition() { if (isLocalPlayer == true) CmdProvidePosToServer(playerTransform.position); } private void LerpRotation() { if (!isLocalPlayer == true) { playerTransform.rotation = Quaternion.Lerp(playerTransform.rotation, syncPlayerRotation, Time.deltaTime * rotationLerpRate); } } [Command] private void CmdProvideRotationToServer(Quaternion playerRotation) { syncPlayerRotation = playerRotation; } [ClientCallback] private void SendRotation() { if (isLocalPlayer) { CmdProvideRotationToServer(playerTransform.rotation); } } } Also the bulletspawn im using is connected to the camera (FPSCamera). thanks in advance for the help!
I think for your CommandFire I would pass all needed data at the time of the shot like position & rotation.