Forum Thread
  Posts  
I want to make a simple multiplayer game (Forums : General Banter : I want to make a simple multiplayer game) Locked
Thread Options
Aug 13 2015 Anchor

I'm really interested in programming video games, but to be honest I've given it a try before(learning I mean) and I couldnt seem to figure anything out. From what I understand... you can do something with just some models(with animation clips) and simple scripts. I wanted to make a game similar to the "Worminator" game from the "Tornado Twins"(which you can check out on youtube(type in Worminator Tornado Twins.)

The first thing I want to do is get some models with animation clips. Then I want to create scripts for movement and animation and firing projectiles and getting hit by the projectiles and subtracting health and respawning. After that is all done I want to make it multiplayer.

If you check out the worminator game from the tornado twins you will see that the models in that video are not animated with animation clips... nor is it multiplayer. I think I can figure out how to make some simple scripts for movement and animation and the combat(which is basically just projectiles and getting hit and subtracting health and respawning.)

... but I don't think I can figure out the multiplayer. I was wonering if someone could just show me a simple way to make a game where the players can connect the host and be given their character.

Aug 13 2015 Anchor

Let's presume you are using PUN (Photon Unity), you would need a "Network Manager" and "Network Player", you can see some tutorials around the internet but basically in the Network Manager you would handle the connection and what to do when joining a lobby/room, for instance:

void Awake()
{
   if (!PhotonNetwork.connected) vConnect();
}

void vConnect()
{
   //I connect using my settings file with the current version.
   PhotonNetwork.ConnectUsingSettings("Version 1");
}

void OnJoinedLobby()
{
   //Do stuff like making/joining a room
}

void OnJoinedRoom()
{
   //Do stuff when joining the room
   vSpawnPlayer();
}

void vSpawnPlayer()
{
   //Find a spawn point, or whatever then...
   //We use photon instantiate so we will be visible to everybody and not just in our screen.
   GameObject Player = PhotonNetwork.Instantiate(sPlayerPrefabName, SpawnPoint.transform.position, Quaternion.identity, 0);
}

Once you spawn the player prefab, you want to make sure some stuff is enabled "only" for the player you are controlling, this may change depending on the type of game you are making, for instance in a 2D ORPG, you would want to disable other players' collision to avoid people from blocking entrances and stuff.
So a simple NetworkPlayer would be...

void Awake()
{
   //If it's "Us", we enable the components that other players in screen don't need to have.
   //That's presuming the prefab initially has everything disabled, otherwise you'd do viceversa.
   if (photonView.isMine)
   {
	myCamera.SetActive(true);
	GetComponent<CircleCollider2D>().enabled = true;
	//...
   }
}

void Update()
{
   if (!photonView.isMine)
   {
      //We smooth the movement with lerp, good for what you want to do but for a humanoid
      //you would want to use Interpolation/Extrapolation.
      transform.position = Vector3.Lerp(transform.position, veRealPosition, fSpeed * Time.deltaTime);
   }
}

public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
   //This is our player.
   if (stream.isWriting)
   {
      //We send our position.
      stream.SendNext(transform.position);
      //Then the direction we are facing, the animation state (bWalking? bFiring? ...), our player's name, etc.

   } else { //This is someone else's player.
     //We get the other players' position smoothed out (previously)
     veRealPosition = (Vector3)stream.ReceiveNext();
     //Then they receive the direction we are facing, animation state, our player's name, ...
   }
}

There's obviously much more to it but those are the basics, it should be enough to be able to see two players on screen, with their smoothed position, name, animations and with some extra lines also their HP.

Aug 13 2015 Anchor

I don't know... too much for me to handle... I wish I had maybe just a project file.

Aug 13 2015 Anchor

I've looked on google and found this: Youtube.com which seems to include a project file as well (In the video's description).

Aug 14 2015 Anchor

I want something that doesn't have all kinds of features. I just want some rigged and animated characters that slide(meaning move) and jump and shoot.

Aug 14 2015 Anchor

"I want something"

Make it then. No one's going to make it for you.

Aug 14 2015 Anchor

Yeah well I can make the characters that jump and move and shoot but I don't know how to make them multiplayer.

Here's a script I have so far it is for a character that moves/jumps/shoots/gets hit and takes damage/dies/respawns. I don't have the translate set to any specific vectors because I'm not sure what x/y/z are in the series nor am I sure how big the integers have to be. Its also not for any specific engine.

Pastebin.com

I want a script that will connect the clients to the server and give the players control of certain game objects.

Edited by: omnisdingin

Reply to thread
click to sign in and post

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.