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 /
avatar image
0
Question by Chris-Waite · Mar 17, 2018 at 05:04 AM · unity 5multiplayerfirst-person-controller

Unity Multiplayer FPS shooting issue.

So im working on an FPS multiplayer project to further build my knowledge on the engine. I ran into a weird issue when spawning two players into the same game. The host of the game operates normally and as it should. It shoots from the correct position which is the end of the barrel of the gun prefab. The client that connects however can shoot. But its not shooting from the correct location. It picks up the X, and Z axis aiming and shooting fine. But when I lift my mouse up on the Y axis, the cursor and crosshair all move. But the shooting of the prefab just goes straight out. I cant shoot in the air. Only straight. Do keep in my mind im using the FPS Controller Unity provides. Also trying to follow the tutorial they have posted for networking. Here is some the code for the shooting.

 private void Update()
         {
             if (!isLocalPlayer)
             {
                 return;
             }
             RotateView();
             // the jump state needs to read here to make sure it is not missed
             if (!m_Jump)
             {
                 m_Jump = CrossPlatformInputManager.GetButtonDown("Jump");
             }
 
             if (!m_PreviouslyGrounded && m_CharacterController.isGrounded)
             {
                 StartCoroutine(m_JumpBob.DoBobCycle());
                 PlayLandingSound();
                 m_MoveDir.y = 0f;
                 m_Jumping = false;
             }
             if (!m_CharacterController.isGrounded && !m_Jumping && m_PreviouslyGrounded)
             {
                 m_MoveDir.y = 0f;
             }
 
             m_PreviouslyGrounded = m_CharacterController.isGrounded;
 
 
             if (Input.GetMouseButtonDown(0))
             {
                 CmdFireWeapon();
             }
         }
 
         [Command]
         public void CmdFireWeapon()
         {
             // Create the Bullet from the Bullet Prefab
             var bullet = (GameObject)Instantiate(
                 bulletPrefab,
                 shootPoint.position,
                 shootPoint.rotation);
 
             // Add velocity to the bullet
             bullet.GetComponent<Rigidbody>().velocity = bullet.transform.forward * 300;
 
             NetworkServer.Spawn(bullet);
 
             // Destroy the bullet after 2 seconds
             Destroy(bullet, 2.0f);
         }

Im not sure why the rotation when I shoot isnt updating. I was thinking it might have something to do with the mouselook that comes with the Standard assets.. Anyone have any idea what is happening, and why the host operates fine, but the client that connects to the host is not?

Comment
Add comment · Show 4
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 Chris-Waite · Mar 17, 2018 at 08:30 PM 0
Share

It is a GameObject attached to the weapon itself yes. Located at the end of the barrel and is attached which is confirmed. As I said its just really weird that the host works 100& proper. The client is what is messing up. It has to be a networking problem on my end.

avatar image hexagonius · Mar 17, 2018 at 09:18 PM 0
Share

the problem is that the actual shooting is happening on the server. it doesn't know where the client is looking at and just instantiates the bullet with its own local coordinates. if you add the actual rotation of the client to the command, the server can instantiate the bullet with the correct orientation.

avatar image Chris-Waite hexagonius · Mar 17, 2018 at 11:53 PM 0
Share

Where would it be that I add that rotation update? Ive tried a few different things and all have failed. Im brand new to networking and stuff so this is all new to me lol

avatar image hexagonius Chris-Waite · Mar 18, 2018 at 06:26 PM 0
Share

add a quaternion parameter to CmdFireWeapon and pass it the necessary rotation. use it IN the command on the server side

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

198 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 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 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 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

Unity 5.2 Unet, extreme Lags after updating from 5.1 1 Answer

Is Unet too heavy for mobile games? 0 Answers

In lobby Manager i have overriden the GameObject OnLobbySeerverCreateGameplayer with 3 prefabs to be chosen by the player How to make each player choose his own character 0 Answers

Unity Multiplayer Oyun Yapma 0 Answers

Multiplayer Respawning Problems 0 Answers


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