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 Addyarb · Sep 02, 2014 at 11:59 PM · networkingupdate

Problem with moving lights on network

Hi Unity,

I'm having issues with rapidly flickering lights when I run my client on a network.

I have a day/night cycle by using a yellow light and a blue light that rotate around the plane with a simple rotate script.(moon and sun). However, when the client runs it, because it's being updated constantly with my position/rotation update script and network view, the lights flicker a few times every second. I'm guessing this is because there's a constant update of the position of it, but why is this happening? How can I fix this?

If I take the networkView and movement update script off completely, the lighting is smooth. However, it doesn't sync with the other clients (which is very important for this game).

Thanks!!

Movement Script:

 using UnityEngine;
 using System.Collections;
 
 /*
 ©2014 Gamer To Game Developer. 
 
 This script is attached to an object and it 
 ensures that the object's position and rotation
 are kept up to date across the network.
 */
 
 public class S2_MovementSync : MonoBehaviour {
     
     //Variables Start___________________________________
     
     private Quaternion updatedRotation;    //Used in capturing the object's last significant rotation.
     private Transform myTransform;        //A reference to the object's transform.
     private Vector3 updatedPosition = new Vector3();
     
     //Variables End_____________________________________
     
     // Use this for initialization
     void Awake () 
     {
         myTransform = transform;
         updatedRotation = myTransform.rotation;
     }
     
     // Update is called once per frame
     void Update () 
     {    
         if(!networkView.isMine && Network.peerType != NetworkPeerType.Disconnected)
         {
             myTransform.rotation = Quaternion.Lerp(myTransform.rotation, updatedRotation, Time.deltaTime*10);
             myTransform.position = Vector3.Lerp(myTransform.position, updatedPosition, Time.deltaTime*12);
         }
     }
     
     void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info) 
     {
         Quaternion rot = new Quaternion();
         Vector3 pos = new Vector3();
                 
         if(stream.isWriting)
         {
             pos = myTransform.position;
             stream.Serialize(ref pos);
             
             rot = myTransform.rotation;
             stream.Serialize(ref rot);
         }
         
         else
         {
             stream.Serialize(ref pos);
             updatedPosition = pos;
         
             stream.Serialize(ref rot);
             updatedRotation = rot;
         }
     }
 }
 

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 mediumal · Sep 03, 2014 at 03:38 PM

Your code looks okay. I suspect the problem is that the clients are also running the code you haven't shown that moves the lights over time, resulting in a tug-of-war. Make sure only the server / offline client runs that code via (false == Network.isClient).

Comment
Add comment · Show 1 · 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 Addyarb · Sep 03, 2014 at 08:16 PM 0
Share

Hi, I think you're on the right track here. I had all of my clients moving (technically rotating) the lights as well as the server. I updated my rotation code to try and resolve this per your suggestion. How does this look? It doesn't seem to work for me, though the flickering is less intense now.

 using UnityEngine;
 using System.Collections;
 
 public class Rotate : $$anonymous$$onoBehaviour {
     public float x;
     public float y;
     public float z;
     void Start () {
     if (Network.isClient == false) {
                         enabled = true;        
                 } else {
                         enabled = false;
                 }
     }
 
     public void RotateLeft()
     {
                 if (!Network.isClient) {
                         transform.localRotation = Quaternion.Slerp (transform.localRotation, transform.localRotation * Quaternion.Euler (x, y, z), 4f * Time.deltaTime);
                 }    
         }
 
     void Update () {
         RotateLeft();
     }
 }
 

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

23 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

Related Questions

UNet Weaver Error, on project updation 1 Answer

Script acting weirdly after updating from 2018.2.2 to 2018.3.1 0 Answers

Unity networking tutorial? 6 Answers

unable to update the below libraries to remove vulnerabilities of APK , How to update the following libraries version for my project to overcome the securities issues 0 Answers

[UNET] Raycast Update lag when Client connect 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