Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Wolfrik_Creations · Nov 27, 2015 at 11:03 AM · javascriptmultiplayercarclient

Multiplayer only host can drive cars?

Okay so I don't use the original Unity 5 multiplayer network manager. I use my own network manager and it's perfectly fine, I've even played with my friend in Canada. I have a problem with my car script and only the person hosting the server can drive. If you are a host you can get in, drive around, get out, it's fine. But if you're a client when you get in the car all it does is play the sitting in car animation and disables your player X rotation and enabled the car cam rotation, but you never actually get in the car or drive it. I launched the Player game, hosted a server, and joined through the editor and it seems to be something to do with line 55 which is the disable player movement line.

Here's the error: NullReferenceException: Object reference not set to an instance of an object CarBehaviour.Update () (at Assets/Scripts/CarScripts/CarBehaviour.js:55)

And here's the code:

 #pragma strict
 
 static var inCar=false;
 private var inPrivateCar=false;
 static var isDriver=true;
 var driverSeat:GameObject;
 var passangerSeat:GameObject;
 var exitPos:GameObject;
 var mlHO:GameObject;
 var speed:float=5;
 var defSpeed:float;
 var topSpeed:float;
 var turnSpeed:float=180;
 var mlH:MouseLook;
 var ml:MouseLook;
 var carIdleSound:AudioClip;
 var carDrivingSound:AudioClip;
 private var useGrav=false;
 var isPlane=false;
 
 function Start () {
     defSpeed=speed;
     GetComponent.<NetworkView>().RPC("CarSounds", RPCMode.All);
 }
 
 function OnTriggerStay (col:Collider) {
     if(GetComponent.<NetworkView>().isMine) {
         if(col.tag=="Player") {
             if(Input.GetKeyUp(KeyCode.E)) {
                 yield WaitForSeconds(0.1);
                 inCar=true;
                 inPrivateCar=true;
                 ml.enabled=false;
             }
         }
     }
 }
 
 function Update () {
     if(GetComponent.<NetworkView>().isMine) {
             if(mlHO==null){mlHO=NetworkManagerScript.globalPlayer.FindWithTag("mlHO");}
             if(mlH==null){mlH=mlHO.GetComponent("MouseLook");}
             if(ml==null){ml=NetworkManagerScript.globalPlayer.GetComponent("MouseLook");}
         if(inCar==true) {
             mlH.enabled=true;
             ml.enabled=false;
         }
         else{
             mlH.enabled=false;
             ml.enabled=true;
             NetworkManagerScript.globalPlayer.transform.rotation.x=0;
             NetworkManagerScript.globalPlayer.transform.rotation.z=0;
         }
         if(inPrivateCar==true) {
             NetworkManagerScript.playerMovement.enabled=false;
             NetworkManagerScript.globalPlayer.GetComponent.<Rigidbody>().useGravity=false;
             NetworkManagerScript.globalPlayer.GetComponent.<Collider>().isTrigger=true;
             NetworkManagerScript.globalPlayer.GetComponent(AudioSource).enabled=false;
             mlH.enabled=true;
             ml.enabled=false;
             NetworkManagerScript.globalPlayer.transform.rotation=driverSeat.transform.rotation;
             if(isDriver==true) {
                 if(isPlane==true) {
                     transform.GetComponent.<Rigidbody>().useGravity=false;
                 }
                 var steer=Input.GetAxis("Horizontal");
                 var throttle=Input.GetAxis("Vertical");
                 NetworkManagerScript.globalPlayer.transform.position=driverSeat.transform.position;
                 NetworkManagerScript.globalPlayer.transform.parent=driverSeat.transform;
                 if(Input.GetKey(KeyCode.W)) {
                     //drive forward
                 } 
                 if (throttle!=0 || speed>=defSpeed) {
             if(!GetComponent.<AudioSource>().isPlaying) {
                     GetComponent.<NetworkView>().RPC("DrivingClip", RPCMode.All);
             }
                     if(speed<=topSpeed) {
                         speed+=0.1f;
                     }
                     if(speed>=topSpeed) {
                         speed=defSpeed;
                     }
                     var moveDist=throttle*speed*Time.deltaTime;
                     var turnAngle=steer * turnSpeed * Time.deltaTime * throttle;
                     transform.rotation.eulerAngles.y+=turnAngle;
                     transform.Translate(Vector3.right*moveDist);
             }
             else{
                 if(speed<=defSpeed) {
                     speed=defSpeed;
                 }
                 if(speed>=defSpeed) {
                     speed-=defSpeed;
                 }
             if(!GetComponent.<AudioSource>().isPlaying && throttle<=0) {
             GetComponent.<NetworkView>().RPC("IdleCLip", RPCMode.All);
             }
             }
             }
             else{
                 NetworkManagerScript.globalPlayer.transform.position=passangerSeat.transform.position;
                 NetworkManagerScript.globalPlayer.transform.parent=driverSeat.transform;
                 NetworkManagerScript.globalPlayer.transform.rotation=passangerSeat.transform.rotation;
             }
             if(Input.GetKeyDown(KeyCode.E)) {
                 NetworkManagerScript.globalPlayer.transform.position=exitPos.transform.position;
                 NetworkManagerScript.globalPlayer.transform.parent=null;
                 mlHO.transform.rotation.y=NetworkManagerScript.globalPlayer.transform.rotation.y;
                 inCar=false;
                 inPrivateCar=false;
             }
         }
         else{
             useGrav=true;
             if(useGrav==true)  {
                 NetworkManagerScript.globalPlayer.GetComponent.<Rigidbody>().useGravity=true;
                 useGrav=false;
             }
             NetworkManagerScript.playerMovement.enabled=true;
             NetworkManagerScript.globalPlayer.GetComponent.<Collider>().isTrigger=false;
             NetworkManagerScript.globalPlayer.GetComponent(AudioSource).enabled=true;
             mlHO.transform.rotation.y=NetworkManagerScript.globalPlayer.transform.rotation.y;
             if(!GetComponent.<AudioSource>().isPlaying) {
             GetComponent.<NetworkView>().RPC("NullClip", RPCMode.All);
             }
         }
     }
 }
 
 @RPC
 function CarSounds () {
     GetComponent.<AudioSource>().Play();
 }
 
 @RPC
 function IdleCLip () {
     GetComponent.<AudioSource>().clip=carIdleSound;
     GetComponent.<AudioSource>().Play();
 }
 
 @RPC
 function DrivingClip () {
     GetComponent.<AudioSource>().clip=carDrivingSound;
     GetComponent.<AudioSource>().Play();
 }
 
 @RPC
 function NullClip () {
     GetComponent.<AudioSource>().Stop();
 }
 
 function OnCollisionEnter (col:Collision) {
     if(col.gameObject.tag=="Col") {
         speed=0;
         yield;
         speed=defSpeed;
     }
 }

Thank you very much for your time and thanks in advance for help or attempt to help! :D

Comment
Add comment · Show 1
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 Wolfrik_Creations · Nov 28, 2015 at 09:34 PM 0
Share

Can someone help please?

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

My car dont move 1 Answer

How to toggle a key for a car to go forward or backward? 1 Answer

Unity Car Tutorial 1 Answer

Convert Car.js from the car tuorial to IOS. 2 Answers

Object Pool on Server not spawning on new Clients (Mirror) 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