This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

OcularCash

DAG Server "Drop And Go Multiplayer"

99 posts in this topic

I saw something in the "Need Help!" Section and I think it's time to clear some stuff with alot of people out there. Making a multiplayer game is very simple, to an extent. There's alot of people out there that want to make there game multiplayer and get confused when doing tutorials and everyone has these scripts that have alot of nonsense, multiple scripts just to connect and lots of bugs and errors. So just to prove a point I'm posting this drop and go multiplayer script. There is literally 2 variables, not 20, and the only variable you need to mess with is the playerGO. Create a camera and place it on your scene. Then put a networkView on your player prefab and drop the prefab into the playerGO variable. Then in your playerMovement and mouseLook script, in the update function before anything, you need to put if(networkView.isMine), then the rest of your code and that will make you control only your player and camera. And looky there, multiplayer. There is no bugs, no errors and is extremely easy to understand because it's only 67 lines. And wait, there is more, when you push quickplay, if a game hasn't been started yet, it will start one. If there is a game started and there is less than 12 players in the server, it will connect to that server, if not, then it will create a new server. O look at that, the easiest multiplayer script on the net and it automatically searches for an available game and doesn't have a bunch of nonsense that you probably would never use with randomized spawn locations. So now that my point is proven, this script is still basic but has a ton of room to add new features and capabilities. So without further ado, here it is:

Please login or register to see this code.

Hope you all enjoy the code. This code is mainly for testing multiplayer with your friends but can be made into alot more. As a heads up, multiplayer in general should not be anything more than 2 scripts. If you have a pregame lobby you will have the connect script and the multiplayerManager "handles score, spawning, players, so on". Anything more is just redundant. Thanks for the support. O and one last thing THIS SHOULD BE ABLE TO BE DROPPED INTO THE FPS KIT WITH MINIMAL TO NO ADJUSTMENT

11 people like this

Share this post


Link to post
Share on other sites

Bit of a problem. It asks me to put the object 'Player' as a prefab in the scene view. However, this enables all the weapons and suddenly EVERY weapon is out at once. I am using the FPS kit 1.2 with a few custom weapons. Help!

Thanks,

- BorDr

Share this post


Link to post
Share on other sites

You use the player prefab that is in the hierarchy and place it into the playerGO slot and make sure there is a networkView on the prefab

A LITTLE INFO ABOUT NETWORKING

The way Networking works is you have "GLOBAL" and "LOCAL" objects. The difference between the two might not seem much, but is actually very different. Local objects are objects that are already in the scene, which is pretty obvious, and what you "the player" sees. Global on the other hand is not the same at all. For instance, if we were in a multiplayer game and I changed or added something that is not called globally "on everyones" then it will only change for me, not for the other places. So if I shoot a bullet and it's not called globally, in my view i can see it and it hit's and calls damage, in yours, no bullet was ever even shot. Another example is viewing the player, in your view, you see just the players arms, in others view, they see your whole body. It's because your using the networkView.isMine to determine what they see and what you see. For instance:

Please login or register to see this code.

Because what your seeing is not actually the users object, you are seeing an instantiated object of how you are to see that object by recording the objects transform and set the mesh.

1 person likes this

Share this post


Link to post
Share on other sites

This looks really cool and makes sense, but where do we put the script?

Share this post


Link to post
Share on other sites

Just create a camera in the scene and put this script on it

Share this post


Link to post
Share on other sites

No need for a tutorial because it's all already explained. But I made an example project to show you Please login or register to see this link.

Share this post


Link to post
Share on other sites

This script is awesome and at the same time so simple... thanks.

On switching to mobile projects the console sends an Ambiguity error.

at this line :

Please login or register to see this code.

to fix it:

Please login or register to see this code.

Max

Share this post


Link to post
Share on other sites

I don't know too much about mobile so thanks for the update

Share this post


Link to post
Share on other sites

Hi,

I have problem with script, I type in X,Y,Z cordinates for spawn point but it spawn's me on totaly different cordinates.

I mean I type in 1800,400,100, and it spawns me at 10,20,10.

Share this post


Link to post
Share on other sites
Please login or register to see this quote.

That's what you changed (in both places)?

spawnPoint = Vector3(1800, 400, 100);

Share this post


Link to post
Share on other sites
Please login or register to see this quote.

comments the two lines:

Please login or register to see this code.

in this way the default random spawn calculation is disabled.

Share this post


Link to post
Share on other sites

I always set my spawnPoints to a random location because in multiplayer, if the spawnPoint is set to the exact position every time, if multiple people spawn at the same time, they will spawn inside of each other. I set this spawn to randomize at a center of 0 "-20 to 20", because 0 "x, y, z coordinates" is the base standard for test maps. In an actual map scenario you would have multiple spawn points "empty GOs" scattered throughout your map in which you would iterate through them to see which ones you can spawn at and choose one of them. Then, choose a random value to spawn between and add it to the chosen spawn so that your players will not spawn on top of each other. Any spawning script will work though but it needs seperate values per player or else you spawn inside multiple players which sometimes causes serious collision issues. For instance, off the top of my head, something that would work is:

Please login or register to see this code.

Just keep in mind, this something completely off the top of my head, not tested. But something similar to this. As a little info to share with you, most large name companies use players tags to determine which spawn is available. For instance, if a player is within a certain distance from a spawn, you simply change the tag of the spawnPoint to something like BlueSpawn or RedSpawn. Inside the spawn section of your player you just spawn at the spawnPoint that has your team name + spawn or team color + spawn. Thought I'd give you a little look into how companies like COD go through this process.

Share this post


Link to post
Share on other sites

Just a question, what if you want to make two teams? how do you spread the people over the 2 teams?

Share this post


Link to post
Share on other sites
Please login or register to see this quote.

Var team = red

spawn at a different place?

1 person likes this

Share this post


Link to post
Share on other sites

lolz, i answer'd my own question xD.. the players connecting to the server > load new level > in level ; defenition of the two teams.. so i don't have to make that system in this script :b

1 person likes this

Share this post


Link to post
Share on other sites

Hey sick code thanks for the help/input - 1 little problem, it wont let me see other players in the game, is this a seperate code i need to make or just simple tags, my prefab is called Player n my camera can see the player TAG if you get what i mean, also does development build affect it?

Share this post


Link to post
Share on other sites

Its ok iv fixed it, dunno how but it works -

Would this work with a spawn management script to make them spawn randomly all over the place?

Share this post


Link to post
Share on other sites

yeah, the code I posted in my last post describes how to randomly choose a spawn in an array of spawns.

Share this post


Link to post
Share on other sites

do you think you could link me to the fps kit you are all talking about, i tried to find it but failed :/ thanks ~~

Share this post


Link to post
Share on other sites

So when I put the if(networkView.isMine) into my look and move scripts does it matter if they are c# or JavaScript or will the code work either way?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now