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 Amazonasmann · May 17, 2019 at 08:04 AM · networkingnetworkplayernetwork instantiate

Unity Networking: Client cant move object but sees everything server does

I am trying to get a simple networking game running in.

What I try to achieve: A 3D object is moved with WASD movement, either server or client can do this and both see the same movement changes.

What I am seeing now is the following: Server can move the object via WASD perfectly fine, the client sees every movement just as expected. Now on the client side I try to move the object via WASD...this works locally, but the server does not see any changes. Once the server moves the object again, the object on the client side gets translated to the position the server sees.


I thought setting "network authority" to "local player authority" would resolve my problem but it didnt. Short version what I did:


  • Create a new 3D object

  • Add NetworkIdentity to it, set "Local Player Authority" to true

  • Add NetworkTransform

  • Add script that moves item via WASD


Content of my script:

     void Update()
     {
         if (Input.GetKeyDown(KeyCode.J))
         {
             Vector3 position = this.transform.position;
             position.x = position.x - speed;
             this.transform.position = position;
         }
         if (Input.GetKeyDown(KeyCode.L))
         {
             Vector3 position = this.transform.position;
             position.x = position.x + speed;
             this.transform.position = position;
         }
         if (Input.GetKeyDown(KeyCode.I))
         {
             Vector3 position = this.transform.position;
             position.y = position.y + speed;
             this.transform.position = position;
         }
         if (Input.GetKeyDown(KeyCode.K))
         {
             Vector3 position = this.transform.position;
             position.y = position.y - speed;
             this.transform.position = position;
         }
     }

Could it be that changing a transform via script needs some kind of trigger to send changes over network? If so, why does work out of the box for the server and not for the client?

Comment
Add comment · Show 1
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 alexxjaz · Aug 01, 2020 at 12:07 AM 0
Share

Did you fix it?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ICY4U · Mar 10, 2021 at 10:08 PM

You have to send the position updates as a command, not sure if it works dont really have time to test but i hope itll help, and yes this is very late lol

     void Update()
          {
              // I added a isLocalPlayer check, remove it if its not supossed to be here, what it basically does is when one client does one of these actions it won't register it as if all other clients did it as well
              if(!isLocalPlayer) return;

              if (Input.GetKeyDown(KeyCode.J))
              {
                  CmdChangeCubePos(new Vector3(-1,0,0);
              }
              if (Input.GetKeyDown(KeyCode.L))
              {
                  CmdChangeCubePos(new Vector3(1,0,0);
              }
              if (Input.GetKeyDown(KeyCode.I))
              {
                  CmdChangeCubePos(new Vector3(0,1,0);
              }
              if (Input.GetKeyDown(KeyCode.K))
              {
                  CmdChangeCubePos(new Vector3(0,-1,0);
              }
          }
     
     // The [Command] tells the server/client its a command meaning it gets sent from the client to the server
     
     [Command]
     void CmdChangeCubePos(Vector3 change)
     {
         Vector3 position = this.transform.position;
         position = position + change * speed
         this.transform.position = position;
     }
Comment
Add comment · Share
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

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

153 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

Related Questions

[Unity Unet ] When spawn Enemy on Server, next thing is how i can change color of this enemy by using OnMouseEnter(), i only run OK on host game, all client can not change color of enemy. Please see code below. 0 Answers

Photon Unity Networking 0 Answers

Sending int variable over a network 0 Answers

【PUN2】I want to disable the instantiation of an object in PhotonView at a specified time. 1 Answer

Adding objects on player models in a multiplayer game 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