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:
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.
//Here would be the part that lets the car move
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.
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).
The question has been closed Jun 12 '12 at 10:24 AM by ExTheSea for the following reason:
Closed because question is to vague and I will maybe find it out myself.
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.
answered Jun 06 '12 at 10:51 PM
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?
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
answered Jun 12 '12 at 10:00 AM
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. :)
answered Jun 11 '12 at 09:37 PM