Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by lordkuba · Feb 07, 2016 at 04:28 PM · networkingspawnshootingclienthost

Networking - Host can spawn objects but client cant

Hi,

I am trying to learn the new networking in unity. I made a small project where you walk around with a cube and shoot spheres forward on mouse click. I followed at least three tutorials on shooting but i'm running into a strange problem. When the host tries to shoot the [Command] void CmdDoFire() executes and the bullet is visible both for the host and the client. Hovewer, when the client tries to shoot, the [Command] void CmdDoFire() does not execute! There are no errors, the whole function just isn't executed at all. I've read dosens of posts about shooting in unity but no one seemed to have a problem like i do. This is the player class:

 using UnityEngine;
 using System.Collections;
 using UnityEngine.Networking;
 using UnityStandardAssets.CrossPlatformInput;
 
 public class PlayerScript : NetworkBehaviour {
 
 
     float moveSpeed = 6.0f;
     float bulletSpeed = 8.0f;
     float lookSpeed = 150.0f;
 
     float fireRate = 0.5f;
     float nextFire = 0;
 
     Camera camera = null;
     Transform head = null;
 
     public GameObject missilePrefab;
 
     void Start () 
     {
         if (!isLocalPlayer)
             return;
 
         head = this.transform.Find ("Head");
 
         camera = Camera.main;
         camera.transform.SetParent (head);
         camera.transform.localPosition = new Vector3 (0, 0, 0);
         camera.transform.rotation = Quaternion.identity;
 
         //Screen.lockCursor = true;
     }
 
     void FixedUpdate () 
     {
         if (!isLocalPlayer)
             return;
 
         Vector3 translation = new Vector3 (CrossPlatformInputManager.GetAxis ("Horizontal") * Time.deltaTime * moveSpeed, 0, CrossPlatformInputManager.GetAxis ("Vertical") * Time.deltaTime * moveSpeed);
         float rotHorizontal = CrossPlatformInputManager.GetAxis("Mouse X") * Time.deltaTime * lookSpeed;
         float rotVertical = -CrossPlatformInputManager.GetAxis("Mouse Y") * Time.deltaTime * lookSpeed;
 
         transform.Translate(translation);
         transform.Rotate (0, rotHorizontal, 0);
 
         head.Rotate (rotVertical, 0, 0);
 
         if(CrossPlatformInputManager.GetButton("Fire1") && Time.fixedTime > nextFire)
         {
             nextFire = Time.fixedTime + fireRate;
 
             CmdDoFire(2.0f);
         }
     }
 
     [Command]
     void CmdDoFire(float lifetime)
     {
         GameObject missile = (GameObject) Instantiate(missilePrefab, head.position, Quaternion.identity);
         Rigidbody rigid = missile.GetComponent<Rigidbody>();
         rigid.velocity = head.forward * bulletSpeed;
         Destroy(missile, lifetime);
 
         NetworkServer.Spawn(missile);
     }
 
     void OnDestroy()
     {
         Screen.lockCursor = false;
     }
 }
 

I am stuck at such a simple thing but I just can't figure out why it doesn't work.

Now I know some people will first mention the simple, often made mistakes. This is what I am sure of:

  • The missile/bullet prefab is in the networkmanager spawnable list

  • Both the player and the missile/bullet have network identities and network transforms

I'd really appreciate if someone know something about this kond of problem.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Guhanesh · Feb 08, 2016 at 11:08 AM 0
Share

did this script attached to Game Player Prefab of network manager game object.And also make sure local player authority is ticked.

avatar image lordkuba Guhanesh · Feb 08, 2016 at 07:20 PM 0
Share

It's a part of the prefab and local player authority is ticked. Thanks for the reply

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

55 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can i Spawn a different prefab for client? 0 Answers

MLAPI Client Character Spawning Problem 0 Answers

Problem with instantiating and declaring objects in Netcode on client 0 Answers

How to correctly change scene with a Lobby Manager? 0 Answers

Networking - How do i spawn an object with client authority? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges