Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Robinhood128 · Sep 09, 2013 at 03:45 PM · movementnetworkingmultiplayer

Movement update doesn't work

I got 3 scripts to update the movement of a player, 1 script on a server another on the object that has to move (the object spawns on the both clients) and the last in a random scene as a Menu;

The problem is if I start the game with 2 clients the objects don't move for eachother. In one of the scripts you'll see PVPC I checked it if that worked and it does work. So if anyone could help me it would be a great help. Because I'm getting no errors.

I parsed alot out of the file that I've normely, because I only gave the parts that can cause the problem and the conncetion to server and other clients works fine.

Server:

 using UnityEngine;
 using System.Collections;
 using System.IO;
 
 public class ServerPVP : MonoBehaviour 
 {   
     //Que1
     int PVPQueN;
     int PVPP1;
     int PVPP2;
     NetworkPlayer player1;
     NetworkPlayer player2;
     
         
     void Start()
     {
         PVPQueN = 0;
         PVPP1 = 1;
         PVPP2 = 2;
     }
     void Update()
     {
         if(PVPQueN < 0)
         {
             PVPQueN = 0;
         }
         
         if(PVPQueN == 2)
         {
             PVPQueN = 0;
             networkView.RPC("StartPVP",player1,player2,PVPP1);
             networkView.RPC("StartPVP",player2,player1,PVPP2);
         }
     
     [RPC]
     void PVPQue(NetworkPlayer Player)
     {
         if(PVPQueN == 1)
         {
             player2 = Player;
             PVPQueN += 1;
         }
         
         if(PVPQueN == 0)
         {
             player1 = Player;
             PVPQueN += 1;
         }
     }
     
     [RPC]
     void StartPVP(NetworkPlayer Player,int PVPp)
     {
         /*if(PVPp == 1)
         {
             PVPP = 1;
         }
         
         if(PVPp == 2)
         {
             PVPP = 2;
         }*/
         //PVPC = Player;
         Application.LoadLevel(3);
     }
     
     [RPC]
     void PVPMove(Vector3 newPosition, Quaternion newRotation, Vector3 newScale, NetworkPlayer PlayerC)
     {
         networkView.RPC("MoveClone", PlayerC, newPosition, newRotation, newScale);
     }
     
     [RPC]
     void MoveClone(Vector3 newPosition, Quaternion newRotation, Vector3 newScale)
     {
         /*myTransform.position = newPosition;
         myTransform.rotation = newRotation;
         myTransform.localScale = newScale;*/
     }
 }

Player:

 using UnityEngine;
 using System.Collections;
 
 public class PVPInterface2 : MonoBehaviour 
 {
     private Vector3 lastPosition;
     private Quaternion lastRotation;
     private Transform myTransform;
     private NetworkPlayer PVPC;
     
     void Start()
     {
         if(networkView.isMine == true)
         {
             myTransform = transform;
             networkView.RPC("PVPMove", RPCMode.Server, myTransform.position, myTransform.rotation, myTransform.localScale, PVPC);
         }
         
         else
         {
             enabled = false;
         }
     }
     
     void Update()
     {
         if(Vector3.Distance(myTransform.position, lastPosition) >= 0.1)
         {
             lastPosition = myTransform.position;
             networkView.RPC("PVPMove", RPCMode.Server, myTransform.position, myTransform.rotation, myTransform.localScale, PVPC);
         }
         
         if(Quaternion.Angle(myTransform.rotation, lastRotation) >= 1)
         {
             lastRotation = myTransform.rotation;
             networkView.RPC("PVPMove", RPCMode.Server,myTransform.position, myTransform.rotation, myTransform.localScale, PVPC);
         }
     }
     
     [RPC]
     void PVPMove(Vector3 newPosition, Quaternion newRotation, Vector3 newScale, NetworkPlayer PlayerC)
     {
         networkView.RPC("MoveClone", PlayerC, newPosition, newRotation, newScale);
     }
     
     [RPC]
     void MoveClone(Vector3 newPosition, Quaternion newRotation, Vector3 newScale)
     {
         myTransform.position = newPosition;
         myTransform.rotation = newRotation;
         myTransform.localScale = newScale;
     }
 }

Client:

using UnityEngine; using System.Collections; using System.IO;

public class Client : MonoBehaviour { public static NetworkPlayer PVPC;

 [RPC]
 void StartPVP(NetworkPlayer Player,int PVPp)
 {
     if(PVPp == 1)
     {
         //This is used for the spawn
         PVPP = 1;
     }
     
     if(PVPp == 2)
     {
         //This is used for the spawn
         PVPP = 2;
     }
     PVPC = Player;
     Application.LoadLevel(3);
 }

}

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

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

15 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

Related Questions

Unity networking tutorial? 6 Answers

Smoothing Network Movement with OnSerializeNetworkView 0 Answers

bouncing a puck of a vertical wall through code 0 Answers

Network Trasnform Interpolation Factor 2 Answers

Rocket Jumping Woes 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