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 oliver-jones · May 21, 2012 at 01:36 PM · multiplayerplayercharactertranslatecontrol

Network - Character Controls

Hi all,

I'm continuing my quest to fully understand Unity's networking. Now, I've got a very simple scene working over a network. Basically, when someone connects, they are spawned a character, in which they can move up, down, left, right and what not. And that character is unique to that user.

The character uses the default third person controllers. Because I want my character to have unique features, I thought I would go ahead and build my own character control script... This is when my network scene started getting 'weird'. Its hard to explain, but it seemed like we were both controlling the same character, but we could both see where we were in the scene. If everyone moves around at the same time, the character would flash continuously back and forth between each of our positions.

Anyway, I assumed it was because of my character controller I built, and that it needs something unique in it? For a start, it doesn't use the 'Character Controller', nor the 'Character Motor', nor the 'FPSInput Controller'. It just has one simple script (that uses Translates and Slerps) a rigidbody, and a box collider.

What am I missing here?

Here is a snippet of my code:

 if(Input.GetAxis("Vertical")){
         //rotate player to face direction arrow
         player.transform.rotation = Quaternion.Slerp(player.transform.rotation, targetRotation, playerRotateSpeed * Time.deltaTime);
         
         //them move player towards arrow direction
         var translation : float = Input.GetAxis("Vertical") * playerMoveSpeed;
         translation *= Time.deltaTime;
         
         player.transform.Translate(0,0,translation);
 
     }

Like I said, I'm trying to get my head around multiplayer... Its always fun to play games with other folks. So I would honestly appreciate any help, or advice. Cheers.

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 ExTheSea · May 21, 2012 at 01:42 PM

try adding to your script in a function Start()

 if(!networkView.IsMine)
      enabled=false;

this way if you added a networkView to the player gameobject the script makes so that you only controls your player. When you make a multiplayer game you should always add this code to scripts that define controls.

When you really whant to understand it read this:

http://unity3d.com/support/documentation/ScriptReference/NetworkView-isMine

Hope this helps.

Comment
Add comment · Show 7 · 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 oliver-jones · May 21, 2012 at 01:52 PM 0
Share

Wow, well that worked like a charm... It seems very laggy though? and I'm running them both on my computer (server/client). I know this is a separate question, but why do you think that is?

avatar image ExTheSea · May 21, 2012 at 02:05 PM 0
Share

Hm i don't think that has to do with the networkView and i also don't think with your movement system. Is it lagging on the screen you controlling it or only for the other one?

avatar image oliver-jones · May 21, 2012 at 05:07 PM 0
Share

On my screen (being the ad$$anonymous$$), I have no lag, but the clients around me do. Same if I go on a client screen, the player doesn't lag, but the other clients and ad$$anonymous$$s do.

avatar image ExTheSea · May 21, 2012 at 06:32 PM 0
Share

You should try it out with another computer/ a friend because if i try networking with to screen on the same computer nothing moves on the other screens. I mean the ones in which i'm not currently controlling anything. $$anonymous$$aybe it's just a reason of the two builds being on the same computer but there could also be a lagg caused by the netcode. In my FPS i sometimes noticed some $$anonymous$$or laggs but they could have also been caused by the bandwith. So try it with a friend/other computer and if that doesn't get rid of the laggs then you had to make your netcode bug-free.

avatar image Bunny83 · May 21, 2012 at 06:40 PM 0
Share

Don't forget to tick "Run in background" or you get in trouble when you switch between two instances of your game ;)

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make camera position relative to a specific target. 1 Answer

non-authorative fps, client controlled character 0 Answers

Moving Rigidbody with Translate causes vibrating player when walking into objects 2 Answers

Php Character list/sessions 0 Answers

Pause online game 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