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 ThatProductionsHD · May 14, 2017 at 07:24 PM · c#unity 5networkingmultiplayernetwork

Pushed back when applying NetworkTransform

Hello world,

I'm working on a FPS game, but i'm stuck on the networking part. This is what happens in the game: The hosts creates a game and can move without problems, also the network part goes right. But when a client joins, you can see the host running, etc.. But the client is always pushed back to the start position.

Scripts:

TransformMotion:

 using UnityEngine;

 [RequireComponent(typeof(TransformMotor))]
 public class TransformMotion : MonoBehaviour
 {

     [SerializeField]
     private float speed = 5f;
     [SerializeField]
     private float lookSensitivity = 3f;

     private TransformMotor motor;

     void Start()
     {
         motor = GetComponent<TransformMotor>();
     }

     void Update()
     {

         // Movement
         float _xMov = Input.GetAxisRaw("Horizontal");
         float _zMov = Input.GetAxisRaw("Vertical");

         Vector3 _movHorizontal = transform.right * _xMov;
         Vector3 _movVertical = transform.forward * _zMov;

         Vector3 _velocity = (_movHorizontal + _movVertical).normalized * speed;

         motor.Move(_velocity);

         // Rotation (around)
         float _yRot = Input.GetAxisRaw("Mouse X");

         Vector3 _rotation = new Vector3(0f, _yRot, 0f) * lookSensitivity;

         motor.Rotate(_rotation);

         // Camera Rotation
         float _xRot = Input.GetAxisRaw("Mouse Y");

         Vector3 _cameraRotation = new Vector3(_xRot, 0f, 0f) * lookSensitivity;

         motor.RotateCamera(_cameraRotation);

     }

 }

TransformMotor:

 using System;
 using UnityEngine;

 [RequireComponent(typeof(Rigidbody))]
 public class TransformMotor : MonoBehaviour
 {

     private Vector3 velocity = Vector3.zero;
     private Vector3 rotation = Vector3.zero;
     private Vector3 cameraRotation = Vector3.zero;

     private Rigidbody rb;

     [SerializeField]
     private Camera cam;

     void Start()
     {
         rb = GetComponent<Rigidbody>();
     }

     public void Move(Vector3 _velocity)
     {
         velocity = _velocity;
     }

     void FixedUpdate()
     {
         PerformMovement();
         PerformRotation();
     }

     void PerformMovement()
     {

         if(velocity != Vector3.zero)
         {
             rb.MovePosition(rb.position + velocity * Time.fixedDeltaTime);
         }

     }

     public void Rotate(Vector3 _rotation)
     {
         rotation = _rotation;
     }

     void PerformRotation()
     {
         rb.MoveRotation(rb.rotation * Quaternion.Euler (rotation));
         if(cam != null)
         {
             cam.transform.Rotate(-cameraRotation);
         }
     }

     public void RotateCamera(Vector3 _cameraRotation)
     {
         cameraRotation = _cameraRotation;
     }

 }
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Matthewj866 · May 14, 2017 at 07:35 PM

You have a few problems here.

Firstly, you need to use NetworkBehaviour and not MonoBehaviour if the class is going to change things over the network.

Secondly, there is no check on the local authority of the object so once this works, any player will be able to move all players.

Did you add your NetworkIdentity object?

Does the game know what prefab is the player prefab?

If this is your first time making anything with UNet I highly recommend having a flick through this tutorial to get the basic idea:

https://unity3d.com/learn/tutorials/topics/multiplayer-networking

Based on the information provided these are the only possible issues I can think of.

Hope this helps.

Comment
Add comment · Show 4 · 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
avatar image ThatProductionsHD · May 15, 2017 at 05:13 AM 0
Share

@$$anonymous$$atthewj866 I have another script for disabling script on join. $$anonymous$$y object has NetworkIDentity indeed. I think the problem is the NetworkTransform component. When i join as a client with my Editor, i'm being pushed back. When disabling the NetworkTransform compenent i can walk without problems, not syncing ofcourse. When i reactivate the component i'm being pushed back to the start position. Any help?

avatar image Matthewj866 ThatProductionsHD · May 15, 2017 at 11:33 AM 0
Share

It definitely sounds like a permissions problem. I still think you should use NetworkBehaviour and do a local authority check rather than disabling scripts on join because NetworkBehaviour classes are allowed to manipulate things on the network.

Can I see the settings on your NetworkTransform, as well as your Network$$anonymous$$anager?

avatar image ThatProductionsHD Matthewj866 · May 15, 2017 at 04:18 PM 0
Share

@$$anonymous$$atthewj866 I added local authority check in the Transform$$anonymous$$otor script but still i got pushed back as a client. Components: alt text

network.png (120.2 kB)
Show more comments

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

7 People are following this question.

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

Related Questions

How do i check which object was instantiated last? 1 Answer

Multiplayer desynchronize when grabbing an object by code. 0 Answers

Photon wont sync for the masterclient. 1 Answer

Can i Call Additive Scene On Network 1 Answer

How to disable the runtime GUI on the Network Manager Hud when you connect to a server?,How do you disable the runtime GUI on the Network Manager Hud when connected to a server 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