Unity character assets don't work in multiplayer - c#

I'm creating an fps game and I want to have multiplayer. I use the standard character assets from unity but when I join my server with more than two players dey cant see the other player move and when they move both players move. It's like the player move script is run on both players at the same time. So if I press w on own of the clients both players move. I'm coding in c#. no error message but in the console it spams "There are 2 audio listeners in the scene. Please ensure there is always exactly one audio listener in the scene."
standard character assets from unity
player network Identity
Network Manager

You're instantiating a controlled player every time someone joins the server. If they have the same controller components, both of the objects are going to react to controls. Create a non-controllable player prefab and have it react to messages sent from the other clients.
If you have a movement component separate from your controller component, you can reuse the movement component on the non-controllable object.

Related

PUN + Standard assets character controller

So, I have 3 scenes a singleplayer scene, a multiplayer scene and a menu scene. When more then one player joins onto the multiplayer scene they both move in the exact same direction. The deafult PUN character controller does not work very well + the tutorial I am using uses the standard assets character controller (which I know is outdated). I think it may be to do with the photon transform view which is nececary for multiplayer wheras in singleplayer without photon transform view/photon view, it works perfectly.
I have tried Changing what is synced but when you exit and reload the prefab nothing has changed.
Please help
Here is a video of my prefab.
https://github.com/JimmyBinoculars/stack/blob/main/2022-12-04%2010-40-33.mkv

How to integrate Ready Player Me with Photon in Unity

I'm using empty Gameobject(Prefab) as a player to instantiate it as a player on the photon server after that i'm using ReadyPlayerMe webgl plugin to load the avatar into the game at the runtime and making it child of PlayerPrefab.. however Photon can detect its position and rotation. but i can't see on other player's screen.
is it possible to load any random object at runtime and show it to all players.. like ReadyPlayerMe avatar

Real time sync in Unity using Photon Unity Network(multiplayer)

Im working on a demo project, where I use Unity 3D and Photon Unity network(PUN) for a real time game.
The person in the top panel is an enemy unit, controlled by another player who does damage to the player on the bottom left (1/3 hp left).
However, the person on the bottom right is a healer who can heal the bottom left player (both controlled by the local player).
Here's my problem! Since it isn't turn based and has to happen real time. How do I design my multiplayer system? Ive previously worked on turn based games, where I just pass the indices and mirror the events taking place locally, in the remote player as well.
But here with latency in the picture, I do not know how to proceed!
What I would like to do is, have the healer heal the player locally as well on the remote player's phone before he is attacked by the remote player or kill the player before the healer can heal his hp depending on the timestamp in which the events happen and reflect such on both the devices.
I think you are confused with some of the pun networking features.
If the healer heals your local player, so will be the remote instances of your local player. Your healing system must be networked of course, make sure you go through our basic tutorial to learn how to implement a simple health system.
https://doc.photonengine.com/en-us/pun/v2/demos-and-tutorials/pun-basics-tutorial/player-networking#health_synchronization
What will be slightly more complex than health management is the switch between your player and healer locally. for this you have two main variants.
transfer ownership between the player and healer: https://doc.photonengine.com/en-us/pun/v1/demos-and-tutorials/package-demos/ownership-transfer (this is a v1 demo but the principle still applies to v2)
have a invisible network player, and using your own logic in your game, have the player matching this invisible network player or the healer matching it.

Detect line of sight and distance between two object in TCP Server

I am developing a 3D multiplayer game. I use Unity 3D as a platform to develop my Game Client. I have to build MySQL C# Console Application which serves me as a TCP server. I am connecting my client via TCP protocol to my Server application. I have the following scenario:
I have two players inside the game both wearing guns and trying to shoot each other.
Between them, there is a wall and Player 1 receives an error when trying to shoot Player 2: "Your target is not in the line of sight." (Normally because there is a wall between them)
However, Player 2 is using "hack" and he removes the wall so he does not receive this error and kills Player 1.
My first question is:
Obviously, it's not a good idea to count only on the client to decide if there is an object between two players to fine and error. What can I do in order my Server App to be able to detect that there is an object between the player and the target? What can you suggest?
My second question is:
How can I calculate the distance between two objects which are in my Server App? Is it possible and if so how?
I imagine that in your server you can access the data of all the users in your Game World. So what you could do it, every time a user claims a hit has been done, you double-check it in the server if that is actually possible.
To do so and find out the distance, you can user Raycasting:
Vector3 direction = (...);
RaycastHit hit;
Vector3 convertDirection = transform.TransformDirection(direction);
if (Physics.Raycast(transform.position, convertDirection, out hit, Mathf.Infinity, layerMask))
{
Debug.Log(hit.distance);
}
Edit: As Rafalon suggested, not sure how cost-efficient is to do this server-side. But you can do it. After all, you are Ironman

syncing a list of already made bullets UNET

I currently have players spawning in with a click to move functionality moving around a space synced perfectly, but I cant get the bullets to sync properly.
When the player spawns in he creates 60 bullets which are then set inactive and stored until an ability is cast, when the ability gets cast I the bullets get sent active and I have a script that syncs them with all the clients as well, but the bullets are only getting set active on the local client, so the SyncPos script doesn't even run.
Do I need to send a message to a separate game object(ie: the net manager) in order to then send a message out to the other clients and say "hey activate this so you can sync it" or is there a better way? and if so how would I go about doing that.
Syncing a game object's active flag over Unet is not supported, because there's no way to find the game object on the other clients since they're inactive. It's like using GameObject.Find(); it can't find inactive objects.

Categories