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 zigol01 · Aug 11, 2017 at 10:25 AM · movementmultiplayermouselook

Mouselook problem multiplayer. Synchronized in 2 computers.

First, sorry for my english. Hello, I have a problem with mouselook in multiplayer game. Both players can move others first person cameras. I fixed movement by using other script which recognize local player and turns on movement script for him, but i cant make the same with camera player. My code for movement looks like this (dont look at comments. Im from poland and its helps my understanding code a little bit better!)

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class MovementAwatara : MonoBehaviour {
 
 
     public float speed = 10.0F; //multiplayer speeda
     static Animator anim;
     void Start () {
         Cursor.lockState = CursorLockMode.Locked; //zablokowanie kursora
         anim = GetComponent<Animator>();
     }
     
     void Update () {
         float horizontalValue = Input.GetAxis ("Horizontal"); //float znajdujący przycisk w prawo i w lewo
         float verticalValue = Input.GetAxis ("Vertical"); //float znajdujący przycisk w góre i w dół
         float translation = Input.GetAxis ("Horizontal") * speed; //float znajdujący przycisk w prawo i w lewo + mnożenie przez multiplayer speeda
         float straffe = Input.GetAxis ("Vertical") * speed; //float znajdujący przycisk w góre i w dół + mnożenie przez multiplayer speeda
 
         translation *= Time.deltaTime;
         straffe *= Time.deltaTime;
 
         transform.Translate(translation, 0, straffe);
         //Chodzenie (Komunikaty i opcje)
 
         if(horizontalValue < 0){ //przycisk w lewo (ładujący się)
             print ("lewo"); //napisz w konsoli unity "lewo"
         }
         if(horizontalValue > 0){ //przycisk w prawo (ładujący się)
             print ("prawo");
         }
         if(verticalValue < 0){ //przycisk w dół (ładujący się)
             print ("dół");
         }
         if(verticalValue > 0){ //przycisk w góre (ładujący się)
             print ("góra");
         }
         if(Input.GetKeyDown("escape")){ //jeżeli kliknięty jest klawisz "escape"
             Cursor.lockState = CursorLockMode.None; //odblokuj kursor
         }
         //Chodzenie
         if(straffe > 0){
             anim.SetBool("Walk", true);
         }
         else
         {
             anim.SetBool("Walk", false);
         }
         
         if(straffe < 0){
             anim.SetBool("BackWalk", true);
         }
         else
         {
             anim.SetBool("BackWalk", false);
         }
 
         if(translation < 0){
             anim.SetBool("LeftWalk", true);
         }
         else
         {
             anim.SetBool("LeftWalk", false);
         }
 
         if(translation > 0){
             anim.SetBool("RightWalk", true);
         }
         else
         {
             anim.SetBool("RightWalk", false);
         }
         
         //Dodatkowe 
         if(Input.GetKeyDown("space")){
             anim.SetTrigger("Jump");
         }
 
         if(Input.GetKeyDown("j")){
             anim.SetTrigger("HouseDance");
         }
 
     }
 }
 

Thats code for my mouse looking script.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class MovementMouse : MonoBehaviour {
 
     Vector2 mouselook;
     Vector2 smoothV;
     public float sensitivity = 3.0F;
     public float smoothing = 2.0F;
 
     GameObject character;
     void Start () {
         character = this.transform.parent.gameObject;
     }
     
     void Update () {
         var md = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y"));
 
         md = Vector2.Scale(md, new Vector2(sensitivity * smoothing, sensitivity * smoothing));
         smoothV.x = Mathf.Lerp(smoothV.x, md.x, 1f / smoothing);
         smoothV.y = Mathf.Lerp(smoothV.y, md.y, 1f / smoothing);
         mouselook += smoothV;
 
         transform.localRotation = Quaternion.AngleAxis(-mouselook.y, Vector3.right);
         character.transform.localRotation = Quaternion.AngleAxis(mouselook.x, character.transform.up);
     }
 }
 

And this is my script for multiplayer per player movement

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.Networking;
 
 public class SterowanieMultiplayerowe : NetworkBehaviour {
 
     void Start () {
         if(isLocalPlayer){
             GetComponent<MovementAwatara>().enabled = true;
         }
     }
     
 }
 

Can somemody help my with this? I will be very happy if someone can! I can explain better and deliver more informations/pictures/code if someone want to help me! Thanks!

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by zigol01 · Aug 11, 2017 at 01:28 PM

The problem is i cant have 2 NetworkIdentity for camera and my avatar. It says its not supported. I dont know how to solve this.

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
avatar image
0

Answer by Phoenix3666 · Jul 17, 2018 at 05:35 AM

I'm trying to figure out how to get around this too, if you find out how, lmk

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

133 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

Related Questions

Multiplayer Mouselook on Soldier (FPS) 0 Answers

Multiplayer - one player is controlling everyone 0 Answers

How to Modify Multiplayer Script for iPhone 0 Answers

How do I add gravity to my object, and how do I fix my network problem? 1 Answer

Players are lagging in Photon multiplayer 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