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 skEncrypt · Oct 08, 2012 at 05:51 PM · multiplayernetworklagchoppyismine

Few questions regarding multiplayer!

Hey guys! I've been making steady progress with my game, I have basic multiplayer functionality at the minute, by this I mean one person can host and the other players can join his game, I'm thinking maybe doing all clients connecting to a proper server would've been better but I'm not sure.

I'll go into depth a bit about my game type, It is a birds-eye Free-for-all arena game, you use click to move to control your character and will press keys to use skills to fight against other players online. There are no guaranteed hitting skills, everything must be aimed correctly whether it be a huge AoE or a small projectile.

Even though I've got this working I have a multitude of problems such as:

  1. Movements are really laggy, not my movements of course but the other players I see are laggy (and they see me as the same!), when you're playing as the host you only really see movement lag but when you play as the person connecting you see movement + projectile lag (such as multiple projectiles showing up instead of 1) I heard that this can be fixed by applying extrapolation/interpolation but I want an extra opinion on the simplest way to make these movements smoother without having to do anything TOO complex, I'm pretty new to Unity but not programming as a whole.

  2. Struggling with certain things when it comes to having to depend on "networkView.IsMine" e.g. I have a skill that activates when a player hits the "W" key, because of the strength of the skill I don't want players to be able to move while casting this so I do something like below on my playerattack script (which is attached to the Player prefab, along with the networkview component

but what happens is when another player is standing near me and I press "W" for the skill, they also are unable to move, here is the code for the skill itself and the code I have for stopping movement while casting the skill:

 [RPC]
 IEnumerator delayedRanged()
 {
     audio.PlayOneShot(shootSound2);
         
     CTM.isCasting = true;
         
     for (int i = 0; i < 40; i++)
     {
         myTransform.localScale *= 1.02f;
     yield return new WaitForSeconds(0.05f);
     }
     
     Debug.Log("Done");
         
     audio.PlayOneShot(shootSound3);
     transform.localScale = originalScale;
     clone = (Transform)Instantiate(projectile, transform.position, transform.rotation);
     clone.localScale *= 20;
         
     Physics.IgnoreCollision(clone.collider, transform.root.collider);
     CTM.isCasting = false;
         
     for (int a = 0; a < 20; a++)
     {
         clone.localScale /= 1.02f;
     yield return new WaitForSeconds(0.05f);
     }
 }

/

 if (networkView.isMine)
 {
     if (!isCasting)
     {
         myTransform.position = Vector3.MoveTowards(myTransform.transform.position, destination, Time.deltaTime * Speed); //move toward destination
     }
 }

These are my main two problems at the moment, I have a few others which I know how to fix myself but these two have me stumped, would really appreciate some tips/help, thanks!

Comment
Add comment · Show 9
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 whydoidoit · Oct 08, 2012 at 06:22 PM 1
Share

Is isCasting as static per chance?

avatar image skEncrypt · Oct 08, 2012 at 07:05 PM 0
Share

Yes, isCasting is static, i couldn't figure out any other way to use cross-script variables, I even tried the example below from the documentation and it still spat out errors.

CT$$anonymous$$ Target; Target.isCasting = true;

 Assets/Scripts/PlayerAttack.cs(110,66): error CS0120: An object reference is required to access non-static member `CT$$anonymous$$.isCasting'


and when it said this I tried to grab the component with GetComponent and it just spat out even more compile errors.

Do you think isCasting being static could be the root of the problem? I didn't think it could trip the variable on the enemy player clients.

avatar image whydoidoit · Oct 08, 2012 at 07:15 PM 0
Share

Yep it can't be a static or if any player is casting then they all are...

Per @Fattie, statics should only be used when you really know what you are doing/need one. In network ga$$anonymous$$g it's totally fraught with problems like the one you are seeing.

avatar image whydoidoit · Oct 08, 2012 at 07:15 PM 0
Share

You need to make the GetComponent work, it will :)

avatar image skEncrypt · Oct 08, 2012 at 07:53 PM 0
Share

Ok thanks guys! Sorry for the late reply was actually showing the game off to a few friends haha, it's co$$anonymous$$g along really well! I'll look through all these links and hopefully get something sorted :) Has anyone any advice for the laggy movement/projectiles? this is really a game breaker, I would prefer to get this fixed before I continue with anything else.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by whydoidoit · Oct 08, 2012 at 08:09 PM

So for laggy movement you want to get the clients to perform the movement, fixing them up as they get more information.

For example:

  • When you connect to the server you record the time offset to the server's time so you have a constant "time" between them

  • When you move you pass the start point, the start time, the end time and the speed of movement

  • Clients then put the player on the path to the target using the real time each frame

  • The moving player then continually sends its current position as it moves

  • The clients fix any errors between their projected position on the track and the position reported at the particular time

Comment
Add comment · Show 3 · 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 skEncrypt · Oct 08, 2012 at 08:17 PM 0
Share

That sounds perfect! Sometimes I just have a hard time planning out the whole procedure but when it's laid out like that it looks simple :)

Thanks! I'm going to go to bed now because I'm super tired but will get to work on this as soon as I get up!

Thanks again.

avatar image whydoidoit · Oct 08, 2012 at 08:31 PM 0
Share

Click to move is one of the easiest things to make "non-laggy" - car driving/plane simulations are the hardest because you need to project the input to the clients and simulate that.

Good luck :)

avatar image Fattie · Oct 09, 2012 at 06:18 AM 0
Share

this is a hugely generous answer

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

11 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

Related Questions

Reducing lag in networking. 1 Answer

Problem - player networking lags 2 Answers

Network Vibration Problem 1 Answer

How can I get "!networkView.isMine" to function properly? 1 Answer

Optimize iPad multiplayer? 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