So as some of you will have seen we just released a Tanks! tutorial game in which players competed on a single keyboard couch multiplayer style.
We couldn’t resist using Unity’s new Multiplayer Networking features to make this demo a 4 player battle arena! We’d love to get your feedback and bugs to make it better - it’s a super basic port right now but it should help you to pick it apart and learn from the code. We’ll be adding features, polishing the UI etc but we wanted to get you this as soon as the port was working.
Download-
UPDATE v1.2
After a brief bugfix, this project is BACK! on the Asset store.
Well theres 2 issues i have with this. Atleast. First off its that you bind color change to the forward direction. which means the player wont get an instant response and said player can hold that forever and only have it happen once.
I rebound it to the y key. and all is gucchi. instant response. Oh yeah forgot to mention, changed all the input.GetButtonUp to GetButtonDown. Because you want an instant response^^
Now your actual pushing isn’t working. This is because your asking the shell for the local player which it won’t ever have because you spawn it and no1 controls it(as my understanding that is)
moved the if(isLocalPlayer)
inside of the for loop and made it. if(targetRigidbody.GetComponent().isLocalPlayer)
And 1 last thing. the line Collider[ ] colliders = Physics.OverlapSphere(transform.position, m_ExplosionRadius, m_TankMask); Will never ever ever ever return anything. Its length will always be 0. Because m_TankMask is only set on the server.
so for the last paramater i just did LayerMask.GetMask(“Players”)
Hi, I’m still learning unity by watching tutorials. Amazing Tutorial, btw!!! I wanted to try the networking demo, so I created a new project, downloaded the networking demo, built the completed scenes. It works like a charm but there are some problems. Can anyone teach me how to solve them. I have already put it on the unity multiplayer service.
I cant change the name of the game in the lobby scene. it stays as new game.
After clicking on the ‘List Servers’ the server name is blank. How do I change that? Why is it blank?
Sometimes one of the players screen doesn’t show the game but shows the loading screen up to round three, but the players tank keeps moving on the other screens when the player presses the move or shoot buttons.
At least one player when moving at the maximum speed, starts repeatedly acting like it is hitting a screen edge buffer everywhere. But, the other players can easily pass through those areas. Also, when the same player is moving slowly (by releasing the button every few seconds and pressing it again) the player doesn’t feel the same effect it was previously feeling.
@Mrinaank 1 & 2 are indeed linked to the fact that the placeholder text doesn’t clear when clicking on an input box. I’ll modify the color to be even more clear that it’s not a value & change it to “Enter a name…” instead.
3 & 4 are a bit more complex ( and not really unet’s fault @scnoobi , as it behaves as expected: syncing stuff as fast as it can; but more my fault & the fact that I tried to keep the sample simple - so no fancy predictions etc…)
3 is definitively a bug. I encountered it before, but though it was fixed. I’ll investigate (thanks for the report!), but if it happen again to you, can you check the log of the clients stuck with the loading screen & tell me if there are any Exceptions (especially null reference exception) somewhere in it?
4 is probably some network problem. Even with broadband speed simulation locally, the problem is minimal here, but on some real network it could be a high ping problem, I suppose.
The way the project works is to use MovePosition to move the tank. So what happens is that
the tank on the client sends its new position to the server
the server smoothly interpolates to that position
but in the meantime, the other has sent a new position
that position can arrive after the tank has reached the previous one, so it was stopped, waiting for new information, hence the stuttering.
Using velocity/force instead of MovePosition could be a way to reduce that, as then the tank will continue to move following its current rigidbody velocity until receiving a new velocity, and so won’t “stop” on server/other client. But I made the decision of keeping the game as close to the non networked one to show the minimal amount of work needed to port a project to multiplayer in its most basic form. A “real” game would probably do something like that, though, as the optimization part…
You can also try to play with snap & interpolation on the NetworkTransform of the tank prefab.
Snap is the max amount the NetworkTransform will try to interpolate smoothly. If between 2 consecutive received positions the tank has moved more than that value, it will be “snapped” (teleported) to that new position. Increasing that could fix some of the problem.
Interpolation is the max delta when interpolating. The highest, the faster the object will move toward it’s position. Reducing it could also reduce the problem.
But mainly remember that in a networking situation, passed a certain ping, there won’t be any miracle…
@UnityGuillaume There is a pretty fatal bug with how you make rooms. It basically makes the game useless for any kind of multiplayer.
The bug: The player counter never reduces itself if a players leaves the room and since at x/x the room won’t show. you has a problem:smile:)
repro:
Start 2 programs. Create a server on 1. the other 1 is client
Join as the client.
now press back(either on connecting or when you have joined the room. Doesn’t matter)
click list servers as client. You will see it is now 2/4. but in your server program it is still you alone.
(I don’t believe it is possible to connect to the room anymore)
Join the room again.
cancel when connecting.
Click list server. It is now 3/4
Join the room. cancel it.
Click list server. It is now not visible.
Okay. not completly unusuable but quite high. Because you only remove the player after said player has been gone for x seconds(dont know how long that is. I believe its like 30-60 seconds)
And this even happens if you back out from the room which is completly unacceptable.
Having it as. if you are not inside the room then we do not count you way of going with this. is way better. because it removes your times. you just got to negate people that are trying to join if the server is already full.
Or reducing the timeout timer and and making the player count go down when a player leaves the room by choice.
Also Still impossible to rejoin the game after you have joined it once. I joined the room once. i then left by click back. i then tried to rejoin. i left the game for 1-2 minutes and was still on connecting. and when i cancel’d i saw that it was at 1/4
Sure! Ill post it as soon as i start the game again (just saw your post). I was wondering if i could use PUN instead of UNET. If so can anyone tell me how, as i’m almost totally new to unity and multiplayer networking.
I’m seeing an issue where the asset for this continually shows as needing an update in the Asset Store, however no matter how often I update it, it remains at version 1.2. Tried manually deleting it and re-downloading, no effect. The asset appears to work just fine, but I saw someone mention a 1.3 above - what is the current version of this tutorial? Is this just an issue on my end (though it’s present on both my Windows workstation and Macbook Pro, so… curious)?
Anyone here encountered problems where tank color aren’t synced or the game doesn’t stop after there only 1 tank left?
I modified the project a lot so I’m wasn’t sure it my fault or the project’s:)