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 Theacesofspades · Dec 09, 2012 at 07:32 AM · networknetworkviewismine

Network FPS Scripting Help

Hey i am new to networking and i did a tutorial on a very basic networking game and it worked perfectly. Now i am trying to make a FPS networking game and i ran into a problem. My problem is that when my player spawns into the map, he cant look around or move, i think i might be using the networkView.isMine in the wrong spots? Here is my script for mouse look:

 function Update () 
 {
     if (networkView.isMine)
     {
         yrotation += Input.GetAxis("Mouse X") * looksensitivity;
         xrotation -= Input.GetAxis("Mouse Y") * looksensitivity;
         
         xrotation = Mathf.Clamp(xrotation, ymin, ymax);
         
         currentxrotation = Mathf.SmoothDamp(currentxrotation, xrotation, xrotationv, looksmoothdamp);
         currentyrotation = Mathf.SmoothDamp(currentyrotation, yrotation, yrotationv, looksmoothdamp);
         
         transform.rotation = Quaternion.Euler(currentxrotation, currentyrotation, 0);
     }
 }

And here is my movement script:

 function Update () 
 {
     if (networkView.isMine)
     {
         horizontalmovement = Vector2(rigidbody.velocity.x, rigidbody.velocity.z);
         if (horizontalmovement.magnitude > maxwalkspeed)
         {
             horizontalmovement = horizontalmovement.normalized;
             horizontalmovement *= maxwalkspeed;
         }
         rigidbody.velocity.x = horizontalmovement.x;
         rigidbody.velocity.z = horizontalmovement.y;
         
         if (grounded)
         {
             rigidbody.velocity.x = Mathf.SmoothDamp(rigidbody.velocity.x, 0, walkdeaccelerationvolx, walkdeacceleration);
             rigidbody.velocity.z = Mathf.SmoothDamp(rigidbody.velocity.z, 0, walkdeaccelerationvolz, walkdeacceleration);
         }
         
         transform.rotation = Quaternion.Euler(0, maincamera.GetComponent(MyMouseLook).currentyrotation, 0);    
         
         if (grounded)
             rigidbody.AddRelativeForce(Input.GetAxis("Horizontal") * walkacceleration, 0, Input.GetAxis("Vertical") * walkacceleration);
         else
             rigidbody.AddRelativeForce(Input.GetAxis("Horizontal") * walkacceleration * walkaccelairratio, 0, Input.GetAxis("Vertical") * walkacceleration * walkaccelairratio);
         
         
         if (Input.GetButtonDown("Jump") && grounded)
         {
             rigidbody.AddForce(0, jumpvelocity, 0);
             Debug.Log("Jumped!");
         }
     }
 }
 
 function OnCollisionStay (collision : Collision)
 {
     if (networkView.isMine)
     {
         for (var contact : ContactPoint in collision.contacts)
         {
             if (Vector3.Angle(contact.normal, Vector3.up) < maxslope)
             {
                 grounded = true;
                 Debug.Log("On the Ground");
             }
         }
     }
 }
 
 function OnCollisionExit ()
 {
     if (networkView.isMine)
     {
         grounded = false;
         Debug.Log("In the Air");
     }
 }




This all works perfect in a single player FPS when i dont use the netoworkView.isMine but not in the networking one that im trying. Can anyone help on what i can do to make this all work? Thanks!

This is the script im using to connect:

 var gameName: String = "Network_Test_1";
 
 var player : GameObject;
 
 private var btnX : float;
 private var btnY : float;
 private var btnW : float;
 private var btnH : float;
 
 private var refreshing : boolean = false;
 private var hostData : HostData[];
 
 function Start ()
 {
     btnX = Screen.width * 0.05;
     btnY = Screen.width * 0.05;
     btnW = Screen.width * 0.1;
     btnH = Screen.width * 0.1;
 }
 
 function StartServer()
 {
     Network.InitializeServer(5, 2500, !Network.HavePublicAddress);
     MasterServer.RegisterHost(gameName, "Networking Tutorial", "This is the Tutorial Test");
 }
 
 function RefreshHostList ()
 {
     MasterServer.RequestHostList (gameName);
     refreshing = true;
     
     
 }
 
 function Update ()
 {
     if (refreshing)
     {
         if (MasterServer.PollHostList().Length > 0)
         {
             refreshing = false;
             Debug.Log(MasterServer.PollHostList().Length);
             hostData = MasterServer.PollHostList();
         }
     }
 }
 
 
 function OnServerInitialized ()
 {
     Debug.Log("Server Initialized");
     
     SpawnPlayer ();
 }
 
 function OnConnectedToServer ()
 {
     SpawnPlayer ();
 }
 
 
 function OnMasterServerEvent (mse : MasterServerEvent)
 {
     if (mse == MasterServerEvent.RegistrationSucceeded)
     {
         Debug.Log("Registered Server");
     }
 }
 
 function SpawnPlayer ()
 {
     Network.Instantiate(player, transform.position, Quaternion.identity, 0);
 }
 
 
 
 function OnGUI ()
 {
     if (!Network.isClient && !Network.isServer)
     {
         if (GUI.Button(Rect(btnX, btnY, btnW, btnH), "Start Server"))
         {
             Debug.Log("Starting Server");
             StartServer ();
         }
         
         if (GUI.Button(Rect(btnX, btnY * 1.2 + btnH, btnW, btnH), "Refresh"))
         {
             Debug.Log("Refreshing");
             RefreshHostList ();
         }
         
         if (hostData)
         {
             for (var i : int = 0; i<hostData.length; i++)
             {
                 if (GUI.Button(Rect(btnX * 1.5 + btnW, btnY * 1.2 + (btnH * i), btnW * 3, btnH * 0.5), hostData[i].gameName))
                 {
                     Network.Connect(hostData[i]);
                 }
             }
         }
     }
 }
Comment
Add comment · Show 5
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 KiraSensei · Dec 09, 2012 at 04:13 PM 0
Share

For a start, do you have a network view attached to your game object ?

Then, ins$$anonymous$$d of always checking if it is your script or another player's, you should try :

function Awake () {

if (!networkView.is$$anonymous$$ine) enabled = false;

}

It avoids to enter the script at every frame...

avatar image Theacesofspades · Dec 09, 2012 at 04:39 PM 0
Share

Yes i do have it attached. And thanks ill try the awake function! Ill let u know how it goes.

avatar image Theacesofspades · Dec 09, 2012 at 06:05 PM 0
Share

So i used the awake function and it works great. But now im getting an error saying: "Failed to Connect. This is caused by an incorrect parameters, internal error or too many existing connections." Any help on what this means? And it cant be because there are too many connections, i set it to where 5 can join and theres only 1 person joining me.

avatar image KiraSensei · Dec 09, 2012 at 06:08 PM 0
Share

Can you edit your question and post the code you are using to connect to the server ?

avatar image Theacesofspades · Dec 10, 2012 at 02:03 AM 0
Share

Alright i posted my connect script.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by guby · Apr 03, 2013 at 06:25 AM

the same thing happened to me but i found out what was wrong it was probably you have too much things in your assets just delete some stuff that you dont need in your assets

Comment
Add comment · 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

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

Multiple Cars not working 1 Answer

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

Does the position change need state synchronization? 2 Answers

One user controls all of them on network 1 Answer

Player 2 not spawning 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