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 /
This question was closed Jun 12, 2012 at 10:24 AM by ExTheSea for the following reason:

Closed because question is to vague and I will maybe find it out myself.

avatar image
1
Question by ExTheSea · Jun 04, 2012 at 12:41 PM · playernetworkvehicle

Entering and Leavinging a Car/Tank/... in an FPS

Closed

Hey guys.

I'm currently making a Multiplayer FPS and I thought about implementing driveable Vehicles. So I made some scripts and they work when there is just one player on a server. But immediatly after another one connects to it it starts bugging out.

The bug is that when you dismount the vehicle the player is stuck in the vehicles-graphic and all of the weapons are equipped. Also the vehicle and the player flies out of the map while spassing out.

The current bug is described in the edit at the end of the question.

Like I said everything works totally fine when there is just one player on the server.

Another thing is that when a player gets into the vehicle and moves around with it the other players don't see it moving and the player does not disappear and stands still.

I hope the demo makes my problem more clear.

Here are the scripts I used:

 var InVehicle: boolean=false;
 var Vehicle: GameObject;
 var cam : Transform;
 function Start () {
 if(!networkView.isMine)
 enabled=false;
 
 cam=Camera.main.transform;
 }
 
 
            ...//The following part gets executed when you press the Use-Key and a raycast hits a car in a predefined range
 
         InVehicle=true;
         Vehicle= hit.collider.gameObject; //gets the gameobject of the vehicle
         
         Vehicle.GetComponent(VehicleMovementScript).enabled=true; // Gets the Movementscript of the vehicle which is also in this question
         if(networkView.isMine)
             Vehicle.Find("DriverCam").GetComponent(Camera).enabled=true;
         var VehicleNV: NetworkView = Vehicle.GetComponent(NetworkView);
         var PlayerObjectNV : NetworkView = PlayerObject.GetComponent(NetworkView);
         VehicleNV.RPC("GetPlayer", RPCMode.AllBuffered, PlayerObjectNV.viewID); //sends the player's viewid to the vehicle
         PlayerObject.SetActiveRecursively(false); // Deactivates the Player
         
         ...
 
 @RPC
 function Dismount() // gets called by the Vehicle when pressed the Use-Key while mounted
 {
 InVehicle=false;
 if(Vehicle!=null){
 
         Vehicle.GetComponent(VehicleMovementScript).enabled=false;
         if(networkView.isMine)
         Vehicle.Find("DriverCam").GetComponent(Camera).enabled=false;
         
 Vehicle=null;
 }
 }

This is the script attached to the player. Its called "VehiclePlayer".

Here is the script "VehicleMovementScript" attached to the vehicle. Its just a cube with a rigidbody and to empty gameobjects. One for the driver and one for the playerDismount.

 var Driver : GameObject;
 var mounted:boolean=false;
 
 function Start () {
 if(!networkView.isMine&&!Driver.networkView.isMine)
 enabled=false;
 }
 
 
 
 function Update () {
 
 

//Here would be the part that lets the car move

 if(Input.GetButtonDown("Use")&&mounted&&networkView.isMine){
 Driver.SetActiveRecursively(true);
 mounted=false;
 Driver.transform.position=transform.Find("DriverDismount").transform.position;
 
 Driver.Find("Main Camera").Find("Weapons").GetComponent(NetworkView).RPC("Dismount",RPCMode.AllBuffered);
 Driver.Find("Main Camera").Find("Weapons").GetComponent(NetworkView).RPC("Reselect",RPCMode.AllBuffered);
 }
 }
 
 @RPC
 function GetPlayer(PlayerObj:NetworkViewID){
 var DriverNV=NetworkView.Find(PlayerObj);
 Driver= DriverNV.observed.gameObject.gameObject;
 mounted=true;
 }

This script calls a function called "Reselect" which is attached to the same gameobject as "VehiclePlayer". This function should select the weapons which are picked up by the player.

Here is the info You recommended I add to the question. It's what I answered to the first answer:

"1. I changed the position the driver dismount various times and 2. It works when only one player is connected, the server. It just starts bugging out when the 2nd player is connected."

I hope someone can help me and debug my code because I couldn't figure it out by myself until this point.

EDIT:

I made some efforts:

I had a line in my update which sets the player at the position of the vehicledriver-Object. I deleted this line and now after leaving the "car" the player gets dismounted like I want him to. The only problem is that the Reselect function gets called at the wrong player. I mean:

Player A gets in Car 1 and dismounts, Reselect wasn't called at player A. Now if player B gets in Car 2 (because car 1 is not mountable at this point[not intended])...and dismounts the Reselect function gets called at player A not at Player B. The same thing happens when Player A then mounts and dismounts Car 1 (which then is mountable again. Car 2 isn't).

Comment
Add comment · Show 13
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 ExTheSea · Jun 04, 2012 at 07:09 PM 0
Share

Is there no one who can debug my code??

avatar image You! · Jun 04, 2012 at 09:02 PM 0
Share

The problem is that this can be a lot to read through... I know I wouldn't be able to help you, but there may be someone who can. You might just have to wait longer, because different people are on at different times of the day. Just check in later, and hope for the best. I'm rooting for you!

avatar image ExTheSea · Jun 04, 2012 at 09:26 PM 0
Share

Thanks for that. It just that I'm struggling so long now to get this done and every time I thing I got it...it ends in the player who dismounts spassing out and flying out of the map.

avatar image You! · Jun 05, 2012 at 05:56 AM 0
Share

...It's better than nothing. I would have no idea how to get that far...but I may have a small idea to help you. Firstly, you can eli$$anonymous$$ate the last script from your post, since it has nothing to do with the problem (obviously, since it has to do with weapon switching, which you seem to have down). (This is only to help with readability of your post. If you need help with it, create a new question for it.)

Here's the idea. $$anonymous$$ounting and dismounting should be animations (since an action should be an animation). This may seem dicey, but you need to destroy the original player object and the original vehicle, and instantiate a new gameobject for both of them for mounting. Dismounting is reverse; do the animation, and then instantiate the original objects to replace the old, "mounted" one (which will be destroyed).

Does this idea help? I wouldn't be able to really code this, BTW.

avatar image ExTheSea · Jun 06, 2012 at 10:30 PM 1
Share

^^ Thanks You you are a big help. You are giving me the strength to stand for my destiny, stand for my question, for UNITY. Now imagine there would be epic music in the background :).

Show more comments

3 Replies

  • Sort: 
avatar image
0

Answer by Piflik · Jun 06, 2012 at 10:51 PM

That's just a wild guess, but if you're using physics and reactivate the player too close to the vehicle when you dismount, he might be pushed away ridiculously fast. Be sure to keep the player outside of the vehicles collider.

Comment
Add comment · Show 2 · 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 ExTheSea · Jun 06, 2012 at 11:12 PM 0
Share

First things first: Thank you for your answer as you are the first one :)

2nd: I don't think this is the problem because 1. I changed the position the driver dismount various times and 2. It works when only one player is connected, the server. It just starts bugging out when the 2nd player is connected.

avatar image You! · Jun 07, 2012 at 03:52 PM 0
Share

@ExTheSea, would you add that info to the question? It surely would be helpful.

avatar image
0

Answer by multinfs · Jun 11, 2012 at 09:37 PM

Well, I can't help you with this since I'm not that into this and are'nt familiar with networking but when I checked out your demo I noticed that the 2nd player cant connect, I tried with the default port to make a server and with another that i know is open and still nothing, i tried selecting the map too but it gets stuck when it says starting game.

Just thought I'd help. :)

Comment
Add comment · Show 2 · 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 ExTheSea · Jun 11, 2012 at 09:48 PM 0
Share

In the web demo I uploaded there is a bug I fixed already. When you wanna try it do it like i described in the question. The Client has to check the map which is played on the server before connecting.

avatar image ExTheSea · Jun 11, 2012 at 10:06 PM 0
Share

I updated it.

avatar image
0

Answer by Bunny83 · Jun 12, 2012 at 10:00 AM

This isn't going to end anytime soon... You provided just some snippets. Network related stuff can be very sensitive. Always keep in mind what happens on what peer.

For example it doesn't make much sense to access Camera.main in a multiplayer game. Camera.main always returns the first camera that is tagged "Main Camera". If you spawn 2 or more players this won't get you the "correct" camera.

There are also some strange things that doesn't make much sense. You enable the VehicleMovementScript on every object but the vehicle's camera only for the player that owns the viewID?

 Vehicle.GetComponent(VehicleMovementScript).enabled = true;
 if(networkView.isMine)
     Vehicle.Find("DriverCam").GetComponent(Camera).enabled = true;

You should do a full evaluation of your code. Make yourself clear what code is executed in which case and when it should be executed. Insert Gebug.Logs that print the players name / viewId at many places in your code to see what get executed by whom and on which pc.

I don't think we get anywhere with that question. It's not really a clear and sepcific question. If you need personal help, post the question on the forums. UnityAnswers is for clear questions that can be answered.

Read the FAQs to see where you should post what

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 ExTheSea · Jun 12, 2012 at 10:25 AM 0
Share

I closed the question and now I will keep trying myself as I'm not that far from solving it. Thx for your answer.

Follow this Question

Answers Answers and Comments

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiplayer| Attaching camera to player (if i am the owner 1 Answer

I cant kill the other player. 1 Answer

Make priority for players 1 Answer

Methods Repeats for each New Player connected 0 Answers

Spawning Player 2 through network and giving it access to another script 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