- Home /
Problem with camera and gun in FPS game
Hi! I'm working on a FPS game and I'm having some problems with the guns and the camera in the multiplayer.
void Awake()
{
players = GameObject.FindGameObjectsWithTag("Player");
foreach(GameObject player in players) {
if (player.networkView.isMine)
if(transform.parent = player.transform)
playerHolding = player; }
if (networkView.isMine) {
countToThrow = -1;
playerTransform = playerHolding.transform;
playerMovementScript = playerHolding.GetComponent();
camerasCheck = GameObject.FindGameObjectsWithTag("MainCamera");
foreach (GameObject cameraCheck in camerasCheck){
if(cameraCheck.networkView.isMine)
cameraObject = cameraCheck; }
}
else
enabled = false;
}
void LateUpdate ()
{ transform.position = cameraObject.transform.position + (Quaternion.Euler(0,targetYRotation,0)*new Vector3(holdSide*ratioHipHold + currentGunBobX, holdHeight*ratioHipHold + currentGunBobY, 0) + Quaternion.Euler(targetXRotation, targetYRotation,0)*new Vector3(0,0, currentRecoilZPos));
targetXRotation = Mathf.SmoothDamp(targetXRotation, cameraObject.GetComponent().xRotation, ref targetXRotationV, rotationSpeed);
targetYRotation = Mathf.SmoothDamp(targetYRotation, cameraObject.GetComponent().yRotation, ref targetYRotationV, rotationSpeed);
transform.rotation = Quaternion.Euler(targetXRotation, targetYRotation, 0);
This is the script that im using for guns in the fps, but when I try to use it on multiplayer the guns start moving crazy and when I shoot when the player that started the scene after the 1st player it looks like if the 1st player is shooting.
I didn't put the whole script cause it's really long.
Thanks!
I think the problem is finding the main camera which belongs to the player.