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
1
Question by danteson · Dec 18, 2014 at 02:40 PM · network

Network. How to get progress of moving platform on client login?

Basicly after i start server and spawn all my moving platforms, if client is not logged in and he logs in abit later after spawning moving platforms, then each player has his own moving platforms, server's is farther in progress and they are not synced at all. That also causes dissapearing for each other, while on moving platform. Huge help would be, if anyone would help me understand,how to get that progress, where is moving platform currently when i login with client, when all moving platforms were already spawned like 5 seconds before me. So when i login there wont be new platform for me from beginning, but already in progress of server's platform :) Thx in advance.

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
Best Answer

Answer by rob5300 · Dec 18, 2014 at 03:30 PM

This should be solved by placing NetworkViews on each of the platforms, and telling the component to observe the transform component (which is done by default).

Now you would only want the server to move the platforms, and the network views make sure that the position is updated on all clients. This can be achieved by checking the bool networkView.isMine. This is true if this is the client that spawned the platforms (only works if Network.Instantiate is used).

This should fix the problem, or alternatively you can use a RPC to send the current position of the platform to the connecting client, and use this data (Vector3) to synchronize them. OnSerializeNetworkView could also help: http://docs.unity3d.com/ScriptReference/Network.OnSerializeNetworkView.html

Comment
Add comment · Show 6 · 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 danteson · Dec 18, 2014 at 04:17 PM 0
Share

Oh so basicly its simpler for me to change whole script? Since i use a script with Original and Destination positions, and the train just rides back and forward with pauses.

avatar image rob5300 · Dec 18, 2014 at 05:33 PM 0
Share

$$anonymous$$ost likely yes, try out having a single script that manages this, and of course design it with multiplayer in $$anonymous$$d and how you wish to make it work over the network. If you need help, just ask or post code you have made if you have problems.

avatar image danteson · Dec 18, 2014 at 06:00 PM 0
Share

I use network instantiate for spawning train like you told me to, and it also has the networkview. I think the problem is in this code:

 using UnityEngine;
 using System.Collections;
 
 public class Train : $$anonymous$$onoBehaviour {
 
     public AudioClip trainAudio;
 
     public GameObject player;
     public GameObject train;
 
     public Transform destinationSpot; 
     public Transform originSpot; 
     public float speed = 5.0f;  
     public float pauseDuration = 0f;
     
     private float platformTimer = 0.0f;
     public bool Switch = false;
 
     private AudioSource audioSource;
 
 
     void Start () {
         audioSource = GetComponent<AudioSource>();
         audioSource.enabled = false;
     }
 
     void OnTriggerStay(Collider other){
         
         if(other.tag == "Player"){
             other.transform.parent = train.transform;
         }
     }
 
     void OnTriggerExit(Collider other){
         
         if(other.tag == "Player"){
             other.transform.parent = null;
         }
     }
 
 
     void FixedUpdate()
     {
         // For these 2 if statements, it's checking the position of the platform.
         // If it's at the destination spot, it sets Switch to true.
         if(transform.position == destinationSpot.position && Switch == false)
         {
             Switch = true;
             platformTimer = 0.0f;
             audioSource.enabled = false;
         }
         if (transform.position == originSpot.position && Switch == true) 
         {
             Switch = false;
             platformTimer = 0.0f;
             audioSource.enabled = false;
         }
         
         // If Switch becomes true, it tells the platform to move to its Origin.
         if(Switch)
         {
             // If the platformTimer is more than the pauseDuration then start 
             // moving the platform else make the platformTImer count up.
             if(platformTimer >= pauseDuration)
             {
                 audioSource.enabled = true;
                 transform.position = Vector3.$$anonymous$$oveTowards(transform.position, originSpot.position, speed * Time.deltaTime);
             }else
             {
                 platformTimer += Time.deltaTime;
             }
         }
         else
         {
             // If Switch is false, it tells the platform to move to the destination.
             
             // If the platformTimer is more than the pauseDuration then start 
             // moving the platform else make the platformTImer count up.
             if(platformTimer >= pauseDuration)
             {
                 audioSource.enabled = true;
                 transform.position = Vector3.$$anonymous$$oveTowards(transform.position, destinationSpot.position, speed * Time.deltaTime);
             } else {
                 platformTimer += Time.deltaTime;
             }
         }
     }
 }


That's complete train code, i quess i should add rpc to movement functions like you suggested(Correct me if im wrong) Then it should work as a charm :) Altho,if it wont,i can use alternative methods for whole script. Thx for your anwser :)

avatar image rob5300 · Dec 18, 2014 at 06:12 PM 0
Share

I think the best way would be to only have the server move the platforms, as they have networkviews, the connected clients trains will be in the same position as on the server, as they are synchronized. This is best as we don't have to mess with the code as much to get them in the same positions when we join the server.

From what i understand, to do this you can simply put this in start

 if(!networkView.is$$anonymous$$ine){
     this.enabled = false;//Should work, never disabled a monobehaviour in the same script before.
 }
 //This should just disable the script on the clients
 //as they don't own this, it isn't not theirs.
 //This will then esure that the movemement to the trains is purely managed by the server, and the clients just have theirs updated.

}

I hope this makes sense, if not, have a look at Networkviews, and how they work, or ask again :)

avatar image danteson · Dec 18, 2014 at 06:26 PM 0
Share

Yeah, i know how they work :) I think i understoon everything. Gonna try it tomorrow. Thx again :) Here's a sneak peak to my project: http://piclair.com/hyeds

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

Handle device offline status 0 Answers

How to make something happen when server deployment fails. 0 Answers

PhotonView question 1 Answer

Android and PHP high scores 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